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!

Count number of characters on a line

Status
Not open for further replies.

craig322

MIS
Apr 19, 2001
108
US
I need to verify how many fields are on a line. Each line should have 210 fields. I tried using awk, but ran into the 199 field limit. Is there a way that I can count the number of | (field delimiters) on each line or the total for the entire file?

TIA

Craig
 
Use nawk instead of awk.

nawk -F\| '{print NF}' filename

Greg.
 
To print lines which don't have 210 fields

nawk -F\| 'NF!=210'

Greg.
 
We do not have nawk installed. Do you have any other thoughts on how to do this?
 
Try something like this:
awk 'gsub("|","|")!=210' /path/to/inputfile

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV, for 210 fields there are only 209 field separators [wink]

[tt]awk 'gsub("|","|")!=209' /path/to/inputfile [/tt]

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top