Counting

Hi,

I want to count how many rows are in a file for a specific column.

eg.

K NM
K NM
K NM
K JK
K NM
K JK
K NM

so the file is tab-delimited. I want to count how many rows are in column 2 and how many NMs there are.

I used awk

awk '{OFS="\t"}; {count[$2]++} {print i, count[i]}' file

but i cant seem to do it for NMs only.

thanks

Ad hoc:

cat input.file | grep 'NM' | wc -l

1) you could filter for the NM with something like

$2=="NM"

or,
2) find count for 2nd field

cat file | cut -d"\t" -f2 | sort | uniq -c

which could be augmented to grep for NM

awk '/NM/{i++;print $2,i}' inputfile