How to truncate empty lines using sed

Sed command is very helpful  for text processing. It’s just matter of regular expression. Here is how you can  truncate empty lines  in the file using command sed.

The above command will give you the output by deleting empty lines. If you want to modify the original file itself. You use the option -i


I have a file with following data and named as numbers

Now see, the way to truncate empty lines using sed

The above command won’t change the original file. If you want to change original use option -i


Sed interprets ‘/^s*$/d’  and giving us the desired output. Here  text between slashes(/regular expression/) represent the regular expression followed by sed command “d”  means delete.  So command sed matches the lines with given regular expression. If it finds the match it applies the command.