How Do I Remove Blank Lines in Unix?
Contents

You can use the -v option with grep to remove the matching empty lines.

How do I remove blank lines in Linux?

The d command in sed can be used to delete the empty lines in a file. Here the ^ specifies the start of the line and $ specifies the end of the line. You can redirect the output of above command and write it into a new file.

How do I delete blank lines in vi?

:g/^$/d – Remove all blank lines.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest