Shell – Delete line if the line has only one column?

Issue

How do I delete the first column (string) if the line has only one string on the first column?

abc def geh
ijk
123 xyz 345
mno

Expected output

abc def geh
123 xyz 345

Solution

A lot of option are available. One of them could be this :

grep " " myfile.txt

The output corresponding of the expected result. This command filter just the line with at least one space.
This works if first string have no space at end, if not this one works too :

awk 'NF > 1' myfile.txt

Answered By – YLR

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published