How to find blank lines in a set of files in GNU/Linux or UNIX-Like Operating Systems

This short script could help you find blank lines at the beginning or the end of a set of files (in this case in the same directory where you run this script).

for f in `find . -type f`; do 
  for t in head tail; do 
    $t -1 $f  |egrep '^[  ]*$' >/dev/null && echo "blank line at the $t of $f"; 
  done; 
done

To run this command:

1) Open your terminal (en GNU/Linux or UNIX-Like OS, it doesn’t work in any Microsoft Windows OS).

2) You can copy and paste the command or if you prefer put it in a single line, go ahead the command also will work!

for f in `find . -type f`; do for t in head tail; do $t -1 $f  |egrep '^[  ]*$' >/dev/null && echo "blank line at the $t of $f"; done; done

 Thanks to the original post in stackoverflow: http://stackoverflow.com/questions/1943727/find-all-files-with-blank-or-ws-at-bof-or-eof

That’s it. Be happy with your code!

Alex Arriaga

Leave a Reply

Your email address will not be published. Required fields are marked *