Skip to content

Remove empty lines in a file

Remove empty lines in a file

Answer

Pick any one of the following methods.

1. grep

grep . test.txt

2. sed

sed '/^$/d' test.txt

3. awk

awk NF test.txt

4. tr

cat test.txt | tr -s "\n"

5. perl

perl -n -e 'print unless /^$/' test.txt

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  1. Remove comments (#) and empty lines in a file
  2. Remove specified lines from a file using sed
  3. How to remove duplicated lines in a file
  4. Create an empty file in Linux
  5. How to create an empty file in Linux

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*