Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting lines in a file

Status
Not open for further replies.

ianicr

IS-IT--Management
Nov 4, 2003
230
GB
I have a file with 500 different postcodes in it. I need to find out how many of each there are. Is there an easy way to do this?
 
man uniq

uniq -c postCodes.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Sorry if i was unclear. An example of the file is
DE1 3FK
DE1 4GK
DE1 4LS
DE5 FKG
DE5 3FJ
DE23 4GK

I need to find out how many DE1, how many de5 and how many de23.

Thanks
 
awk '{a[$1]++} END {for(x in a) print a[x],x}' fileA
 
awk '{print $1}' postCodes.txt | sort | uniq -c

Don't forget to sort before using uniq - if already in order, then you don't have to.


Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top