To remove all blank lines from a file we can use sed command.
There are 2 ways to delete blank lines with sed
- Removing blank lines within the file.
- Redirecting std out to new file by removing blank lines from input file.
Example to removing blank lines within the file:
$ sed -i '/^$/d' INPUT_FILE
Example to redirect std out by removing blank lines from input file:
$ sed '/^$/d' INPUT_FILE > NEW_FILE or $ cat INPUT_FILE | sed '/^$/d' > NEW_FILE
-Sany
Advertisements
Thanks for the tips. It is also possible to remove blank lines using the Linux tool vi. If you have the file open you can simple type :1,$s/^$/d
Thanks for the update.