Nix: Count the number of fields in a record
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.
Leave a comment