Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete line if no data in all columns?

Status
Not open for further replies.

rhnaeco

Technical User
Aug 11, 2005
45
hi, I have a file which has been been created by a series of awk and sed commands which should have 4 columns.

unfortunately some lines have some data missing and thus only have 2 or 3 columns.

the subsequent running of a fortran script doesn't like this change and it exits.

so far i have been using GMT's minmax command to find these rogue lines in order to delete them, but it's becoming tedious.

Is there a way that awk (or sed) can sort through the files and only print the correct lines with 4 columns?

thanks in advance
 
awk 'NF==4' /path/to/input >output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hello, rhnaeco!

You can try this

Code:
awk 'NF > 3' file[s]

or (if you wish to see filename)

Code:
awk 'NF > 3 { print FILENAME, $0 }' file[s]


Jesus loves you. Bye!

KP.
 
thanks to both of you, problem solved!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top