Count number of column in a pipe delimited file
awk, linux, perl, shell
Solution
awk -F\| '{print NF}'
gives correct result.
Problem
I have a pipe `|` delimited file. File: ``` 106232145|"medicare"|"medicare,medicaid"|789 ``` I would like to count the number of fields in each line. I tried the below code Code: ``` awk -F '|' '{print NF-1}' ``` This returns me the result as 5 instead of 4. This is because the awk takes "medicare|medicaid" as two different fields instead of one field