Calculating no. of columns in a flat file

Hi,

I want to find out the no. of columns in a flat file. If it is "," delimited, I am using
awk -F\\, '{print NF;exit}' filename.txt
which is giving me correct results.

But the delimiter can be either comma or pipe delimited. How can I make that provision in Unix?
sunny82Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
woolmilkporcConnect With a Mentor Commented:
awk -F"[,|]" '{print NF;exit}' filename.txt

wmp
0
 
sunny82Author Commented:
Many thanks, it worked great!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.