Sachin shinde Sachin shinde - 4 years ago 123
Bash Question

Counting the number of rows of having one column values are matching

I want to calculate the number of rows having same value in first column but different in second column using either shell script or awk.
For e.g. File consists of

400.00 1234
400.00 2134
400.05 4314
400.05 9766


Hence count should be 2,2,......

Answer Source

What about using uniq's counting option:

$ awk '{print $1}' inputfile | uniq -c
      2 400.00
      2 400.05

This assumes that in the first column all identical values appear sequentially. If this is not the case you can sort the input numerically before piping into awk.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download