Suppose we'd like a list of relatively common five letter words.
Here's how we might proceed.
$more twofull a 2497 aardvark 0 aback 2 abacus 1 abaft 1 abalienate 1 abalienation 1 abandon 10 abandoned 3 abandonment 4 |
We find a file that has some (apparently) useful data in it. |
$w=/homes/ddailey/public_html/$w |
We define a variable to point to the file for further investigation. |
$wc twofull 35915 71828 406298 twofull $grep ^.....\ [0123456789]*$ $w|head aback 2 abaft 1 abase 2 abash 2 $grep ^.....\ [0123456789]*$ $w|wc 2949 5898 24067 |
We poke at it a bit. See how big the file is; see if we can find five-letter words; and, if we can, see how many of them there are. |
$grep ^.....\ [0123456789]*$ $w>fivefreq |
Feeling cavalier in our success, we now cast the moment in stone, grabbing the data into our own little file. |
$for i in 0 1 2 3 4 5 6 > do > echo $i `grep -c $i fivefreq` > done 0 502 1 1035 2 506 3 360 4 275 5 214 6 149 |
A quick loop gives us some idea of the distribution of frequency data as conveyed by this file. [Note: this counts digits like '0' that might also occur in '10', and is, hence suggestive rather than accurate.] |
$grep ' '0 fivefreq|head -able 0 acorn 0 aggro 0 agora 0 ain't 0 angst 0 anise 0 anode 0 anti- 0 aptly 0 |
A look at some of the low frequency words (those in the word list which had no presence in the corpus used -- Roget's 1911) may confirm what we suspect anyhow: that we can throw those words away. Similar investigations may reveal that words with frequency 1 and 2 are, likewise, unwanted for our purpose. |
$for i in 0 1 2 3 4
> do
> echo number greater than $i \
> `awk '{if ( $2 >= p ) print $0}' p=$i \
> fivefreq|wc -l`
> done
number greater than 0 2949
number greater than 1 2506
number greater than 2 1754
number greater than 3 1385
number greater than 4 1114
|
A more precise count of words with frequency greater than or equal to a given number. |
$awk '{if ( $2 >= 3 ) print $0}' fivefreq|wc
1385 2770 11555
|
Specifically, for p=3, we will have a file of 1385 words with frequency >=p. |
$awk '{if ( $2 >= 3 ) print $0}' fivefreq|head
abide 15
abode 17
about 132
above 24
abuse 16
abyss 3
acrid 6
actor 9
acute 14
adapt 4
|
Take a peek to make sure they are the right sort of stuff. |
$awk '{if ( $2 >= 3 ) print $1}' fivefreq>common5
[public_html]$wc common5
1385 1385 8310 common5
|
Grab the words (and verify that the numbers look right) -- 1385 x 6 = 8310 ! (5 chars and a '\n'). |