FAQ : How to use grep command to remove blank lines from file
Answer: To remove the blank lines from file, use the given below syntax

grep -v '^$' /path/of/file-name

In above command,

-v = Invert the sense of matching, to select non-matching lines
^$ = It is regex. ^ means start with and $ means end with. Combining both ^$ means blank lines

Example (With screenshot):

In below given file, contents have some lines in between

grep command

Now using grep command to remove blank line from file.

grep

Learn more about grep command in our blog. Click Here.

Read Some More Articles

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.