About this site
Links to us
General :: Linux :: shell
Linux shell programming/ scripting, shortcuts and general know-how.
This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Generated 8:00:33 on Aug 11, 2020
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
|Most recent comments