Is there a way to get awk to return the number of fields that meet a field-separator criteria? Say, for instance, the file contains:
a b c d
So, awk -F=' ' | <something> should return 4.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
NFvariable is set to the total number of fields in the input record. So:echo "a b c d" | awk --field-separator=" " "{ print NF }"will display
Note, however, that:
echo -e "a b c d\na b" | awk --field-separator=" " "{ print NF }"will display:
Hope this helps, and happy awking