Computing.Net > Forums > Unix > unix: count unique fields in column

unix: count unique fields in column

Reply to Message Icon

Original Message
Name: Big_Z
Date: March 20, 2007 at 13:06:02 Pacific
Subject: unix: count unique fields in column
OS: AIX 5.3
CPU/Ram: RISC/1GB
Comment:

Hello, I have output similar to the following:

Bob 0400 0320
Bob 0420 0320
Bob 0425 0319
Jill 2300 0319
Joe 1100 0320
Bob 1300 0319
Sue 2115 0319
Sue 2100 0319
Joe 1100 0318

And the list continues on and on with different "names" in column 1. I want to display a count of each unique name in column 1 and show in a simple report. Example, if Bob shows up 10 times, Sue 8 times, and Jill 3 times I want the report to look like this:

Bob 10
Sue 8
Jill 3

Thanks for any assistance with this!


Report Offensive Message For Removal

Response Number 1
Name: nails
Date: March 20, 2007 at 13:43:15 Pacific
Subject: unix: count unique fields in column
Reply: (edit)

Use awk's associative arrays:


awk ' { per[$1] += 1 }
END { for (i in per)
print i, per[i] } ' myfile


Report Offensive Follow Up For Removal

Response Number 2
Name: srinadh
Date: April 7, 2007 at 08:02:31 Pacific
Subject: unix: count unique fields in column
Reply: (edit)

can u explain the above given code

sree


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: unix: count unique fields in column

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software