Thursday, February 14, 2008

How to create a histogram using awk

Command:

awk ' NF > 0{ counts[$0] = counts[$0] + 1; } END { for (word in counts) print word, counts[word]; }' FILE.DAT

Example:
FILE.DAT
--------
A
B
C
A
B
B


The result:
A 2
B 3
C 1

1 komentárov:

Anonymous said...

I really like your blog and i really appreciate the excellent quality content you are posting here for free for your online readers. thanks peace claudia.