Tuesday, October 25, 2022

[SOLVED] Delete lines that contain only spaces

Issue

Consider following file.

Dalot
# Really empty line
Eriksen
   # Line containing space
Malacia
        # Line containing tab
# Really empty line
Varane

How do I remove line that ONLY contain either whitespace or tab on it, and leaving empty line intact. The other answer here mostly will remove all empty line including spaces and tab.

Following is desired output.

Dalot
# Really empty line
Eriksen
Malacia 
# Really empty line
Varane

Solution

Using awk:

awk '/^$/ || NF' file


Answered By - oguz ismail
Answer Checked By - Cary Denson (WPSolving Admin)