torek, 06. november 2012

Remove empty lines from a file on Linux using command line

This one is especially useful when searching through Glassfish's log files.
There are many ways you can remove empty lines from a file:

  • awk 'NF' file
  • sed '/^$/d' file
  • grep "^$" -v file
  • grep . file
  • egrep "^[[:space:]]?$" -v file
  • perl -n -e 'print unless /^\s*$/' file
And I'm sure there are many more. :)
Objavite komentar