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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Number of Occurrences in a File 2

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi There!
Could someone help me out on this? For Example, I have a file which contain the details as shown below:

ABCD
BCDE
DEFG
BCDE
ABCD
ABCD
DEFG

How Can I Sort this File out such that I have the following output counting the number of occurences of the particular line in the file:

ABCD 3
BCDE 2
DEFG 2

Thanks A lot!

Regards,
klstra
 
BEGIN {
}

{ arr[$0]++ }

END {
for (i in arr)
printf("%s%s%s\n", i, FS, arr);
}
 
I know this is the awk forum but don't forget that if you are on a unix box the command "uniq" will do the same thing for you (if you first sort it). uniq -c or some such option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top