Remove blank lines from a file using grep

Posted September 15, 2003 by Quinn McHenry in UNIX

Last Updated on

How can I remove blank lines from a file in UNIX?

grep -v "^$" filename > newfilename

The ^$ within the quotes is a regular expression: ^=beginning of line, $=end of line, with no characters between.

See additional helpful information in the comments below.


About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

Leave a Reply