Linux / Unix: Shell Remove Empty Lines

To remove empty lines from a text file in Linux or Unix, you can use the following command:

grep . file.txt > output.txt

This command uses grep to search for lines that contain a period . and writes the matching lines to a new file called output.txt. This effectively removes all empty lines from the input file file.txt.

Note: The original file is not modified. The filtered output is written to a new file called output.txt. You can replace the output file name output.txt with any other name as desired.

Leave a Comment