Count the number of fields in column

Hi
I was going through the below thread

I too have something similar requirement as specified in this thread but the number of columns in my case can be very high, so I am getting following error.

 
user1 [/aaaa/bbb] $ --> awk -F'|' '{print NF}' myfile.txt
awk: record `AAAAAAAAA|B|CCCCCC|DDDDDDDD...' has too many fields

Any other way to achieve or it is a limitation for awk command.

regards
jc

I did a search on this forum , and got

 
Documentation says 99 is the max value for NF:
 
HPUX 11.0 awk supports 199. gawk on our old RH box is 255.
 
As you may guess, there are several versions of awk.

You can use, cut instead of awk.(Few limitations here however).

2 Likes

Thanks Panyam,

I tried in another method and it worked.

head -1 file | sed 's/[^|]//g' | wc -c

Regards

Be aware that that's not equivalent to AWK' NF. It's actually NF-1. The number of fields is one more than the number of delimiters.

Regards,
Alister