FreeKB - do something empty lines
Bash Shell Scripting - do something empty lines

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


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments