When working with file manipulation in Linux system, may needed to remove empty lines from a file to make it easier to read or to be processed further. This tutorial shows how to do that.
Create a new file for testing:
printf "Line1\n\nLine2\n\nLine3\n" > test.txt
The sed
command can be used for files processing. Run the following command to remove empty lines from a file:
sed -i '/^$/d' test.txt
The -i
option will edit file in-place.
Leave a Comment
Cancel reply