|Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides
|How to get the word frequency in a text
|Page 1 of 1|
|Author:||LaR3 [ Wed Aug 05, 2009 7:01 am ]|
|Post subject:||How to get the word frequency in a text|
In my previous post http://forum.ivorde.ro/tr-how-to-convert-a-text-into-a-list-of-words-one-per-line-t17.html I explained how to convert a text into a list of words, with one word per line.
This is how to get the word frequency in a text:
# cat test.file
FreeBSD 7.2-RELEASE is now available for the amd64, i386, ia64, pc98, powerpc, and sparc64 architectures.
FreeBSD 7.2 can be installed from bootable ISO images or over the network; the required files can be downloaded via FTP or BitTorrent as described in the sections below. While some of the smaller FTP mirrors may not carry all architectures, they will all generally contain the more common ones, such as i386 and amd64.
# cat test.file | tr -d '[:punct:]' | tr ' ' '\n' | tr 'A-Z' 'a-z' | sort | uniq -c | sort -rn
What I did was to convert all upper case letters to lowercase (because I don't need duplicate words because of one or more letters in different case) and then sort all the words and sent the output to uniq (-c Precede each output line with the count of the number of time the line occurred in the input, followed by a single space.). Then I sorted all the output numerically in descending order.
|Page 1 of 1||All times are UTC - 5 hours [ DST ]|
|Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group