The problem is that your target field has embedded double quotes, so you need to match them too, by including them - \
-escaped - in the string to match against:
awk '
BEGIN{FS=","; s_count=0; c_count=0}
($3=="\"s\"") {s_count++}
($3=="\"c\"") {c_count++}
END{ print s_count; print c_count }
' data.csv
As an aside, you can simplify your awk
program somewhat:
- the parentheses are not needed (have not verified on
cygwin
, but given that it'sawk
interpreting the string, I wouldn't expect that to matter) - you don't strictly need to initialize your output variables, because
awk
defaults uninitialized variables to0
in numerical contexts.
BEGIN{FS=","}
$3 == "\"s\"" {s_count++}
$3 == "\"c\"" {c_count++}
END{ print s_count; print c_count }