Bootstrap FreeKB - Bash (Scripting) - do something empty lines (sed)
Bash (Scripting) - do something empty lines (sed)

Updated:   |  Bash (Scripting) articles

Let's say file.txt contains empty lines.

line 1

line 3

line 5

line 7

 

The following sed command will remove the empty lines. The regular expression looks for the beginning (^) of a line immediately followed by the end ($) of a line, and if matched, deletes (d) the line.

~]# sed '/^$/d' file.txt
line 1
line 3
line 5
line 7

 

Remember that the -i option must be used to actually perform this change on the file.

~]# sed -i '/^$/d' file.txt
line 1
line 3
line 5
line 7



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 0ecf55 in the box below so that we can be sure you are a human.