csv - How to get the record count of columns matching with particualr value using awk command in linux -
i have display record count of columns matching "cd" input csv file. value cd appearing in second column in file input.csv.
i trying below command not working expected.
awk -f',' '$2=/cd/ { count++ } end { print count }' input.csv
my input data:
1234,cd,xyz,abcd 01235,ab,kasdjk,aaaaa,fff 898,cd,laklksas,lsjdjdj,lkjsaj 111,cd,lkakskaks,jjjjjj 3455,00,ksajkjsa,kkkkk 59995,99,asllsal,99898,00,kkk,99 99,00,lkjjjsa,00,99,hhhh
expected output:
3 if check count of "cd" 2 if check count of "00"
please me.
the operator match regexp ~
, not =
.
awk -f',' '$2 ~ /cd/ { count++ } end { print count }' input.csv
if want exact match, not regular expression, use ==
, string:
awk -f',' '$2 == "cd" { count++ } end { print count }' input.csv
=
assigning, not comparing.
Comments
Post a Comment