For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2004 > Re: Count and display the frequency of occurance of each letter in









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Count and display the frequency of occurance of each letter in
Ed Morton

2004-05-12, 7:19 pm



Cityhunters wrote:
<snip>
<snip>[color=darkred]
> Thanks guys^_^~finally i manage to solve this problem with all the
> hints ...
> my solution is :
>
> awk 'BEGIN{FS=""}{for(i=1;i <=NF;i++)count[$i]++}END{for(word in
> count)print count[word],word|"sort -nr" }' fileName


You should change count[$i] to count[tolower($i)] since you want to be
case-insensitive. You should also use "letter" instead of "word" as your
variable name. I don't know if makes any difference, but you could also
move the "| sort -nr" outside of the awk script.

Ed.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com