[geeks] text file processing

R. Lonstein ross-sunhelp at lonsteins.com
Tue Jan 6 13:08:59 CST 2004


On Tue, Jan 06, 2004 at 12:27:07PM -0600, Bill Bradford wrote:
> Anybody know how to run a text file through some sort of processor and find
> the most-used strings or words?

Quick and dirty... generates a descending list, prefixed by the
count:

perl -ane 'foreach (@F) { $h{$_}++ }; END{ foreach (reverse sort { $h{$a} <=> $h{$b} } keys %h) { print $h{$_}," ",$_,"\n";} }' <filename>

- Ross



More information about the geeks mailing list