You can use any one of the following utility to delete all empty lines from text file:
[a] sed command
[b] awk command
[c] perl command
Syntax
The syntax is:
command input.txt > output.txt
command [option] input.txt > output.txt
sed '...' input.txt > output.txt
## Gnu/sed
sed -i '...' input.txt
awk '...' input.txt > output.txt
sed command examples
Type the following sed command to delete all empty files:
sed '/^$/d' input.txt > output.txt
cat output.txt
OR
sed -i '/^$/d' input.txt
cat input.txt
awk command examples
Type the following awk command to delete all empty files:
awk 'NF > 0' input.txt > output.txt
cat output.txt
perl command examples
Type the following perl one liner to delete all empty files and save orignal file as input.txt.backup:
perl -i.backup -n -e "print if /\S/" input.txt
Verify updated files, type:
cat input.txt
cat input.txt.backup