1753538 Members
4922 Online
108795 Solutions
New Discussion юеВ

Re: column count in awk

 
SOLVED
Go to solution
Christian Marquardt_1
Regular Advisor

column count in awk

Hello,
I've a script with awk reading lines from a file. Sometimes the line has 9 columns, sometimes 8.
Does anyone know how to get the total number of the columns in the actually read line???
Is there any variable like $? ....????

Kind regards
Christian
4 REPLIES 4
Peter Godron
Honored Contributor
Solution

Re: column count in awk

Christian,
NF is the one.
Example:
awk '{ for (i = NF; i > 0; --i) print $i }' file

Print columns in reverse order
spex
Honored Contributor

Re: column count in awk

Hi Christian,

awk '{print NF}'
PCS
Christian Marquardt_1
Regular Advisor

Re: column count in awk

Thanks a lot ... that's what I need!

kind regards
Christian
Christian Marquardt_1
Regular Advisor

Re: column count in awk

everything is cool