less than 1 minute read

To count the number of fields in a delimiter-separated text file, use awk:

>>> cat temp.txt
|28-07-1997|IF_LEG_DCCT|TOV JV sdfsdfdsfdsfdsCLOSED* KIEV|381015280
>>> awk -F '|' '{print NF}' temp.txt
5

NF is a variable with the number of fields in the current record. The -F option is used to specify the file delimiter, and the default delimiter is a space.

Via unix.com.

Tags: , ,

Categories:

Updated:

Leave a comment