shell

Removing blank lines from a file

Sometimes I need to remove blank lines from a specific file. I usually do it with the two following commands:

$ grep -v "^$" file

or

$ sed '/^$/d' file

Obviously, if you want to save the output you should redirect it to another file, for example:

$ sed '/^$/d' file1 > file2

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields