DelphiFAQ Home Search:
General :: Linux :: shell
Linux shell programming/ scripting, shortcuts and general know-how.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

How to remove blank lines from a text file (in Unix)

Question:

I need to remove all blank lines from a huge text file on a unix system. What's the easiest way to achieve this?

Answer:

Use the command line text editor sed and issue the statement shown below.
It will create a temporary file, afterwards replace the original file with it.

# the following uses the editor sed to find blank lines
 # and delete them:
 
 # in the regex ^ means beginning of line, 
 # and $ means end of line
 
 sed '/^$/d' myfile.txt >newfile.txt
 mv newfile.txt myfile.txt

Generated 12:00:38 on Dec 11, 2017