sed

All posts tagged sed

This is a common task for every administrator. We have a large file with many empty lines. We want to remove them.

$ cat ./file.txt
Line 1

Line 2
Line 3
Line 4

Line 5
Line 6

Line 7
Line 8
Line 9

Line 10

This command removes all empty lines or those that contain only whitespace characters.

$ sed '/^\s*$/d' ./file.txt 
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

Simple and useful!