More fun with grep (sorting, head, tail, loops).

grepping and sorting

command/output explanation
$ grep o' ' $f|sort -r|more
# requires special permission ...
# Permission to distribute ...
 2078      4  to  (prep,adv)
  369     76  go  (v,n)  ~
  356     55  into  (prep)
  230     51  no  (adj,adv,n)
  169     65  do  (v,n)  ~
   52    107  too  (adv)
   51     46  who  (pron)
   51     44  so  (adv)
   38    131  two  (n,adj)
   28  21738  o  (interj)
   19  10481  echo  (n,v) 
Find the words ending in 'o' and display in order of their frequency.

 

grep ^[abcde].*by$ $w
abby
baby
bobby
booby
chubby
cubby
derby       
verify that the output makes sense

grepping in a loop

command/output explanation
$w=/homes/share/words-english
$ for i in a b c d e
> do
> grep ^$i.*by$ $w |wc
> echo $i
> done
      1       1       5
a
      3       3      17
b
      2       2      13
c
      1       1       6
d
      0       0       0
e                    
redefine $i successively as 'a', 'b', 'c', 'd', and 'e'

repeat the commands following 'do' for each value of $i

look for words in the dictionary beginning with  $i and ending with 'by'; count them

show the value of $i as we go

Improvement over the above:
$for i in a b c d e
> do
> a=`grep ^$i.*by$ $w|wc -l`
> b=`grep ^$i.*by$ $w|head -1`
> echo $i\.\*by\$ \(as in $b\) occurs $a times
> done
a.*by$ (as in abby) occurs 1 times
b.*by$ (as in baby) occurs 3 times
c.*by$ (as in chubby) occurs 2 times
d.*by$ (as in derby) occurs 1 times
e.*by$ (as in ) occurs 0 times
The output from certain commands is stored in variables and later echoed in a more readable form.
grep ^[abcde].*by$ $w
abby
baby
bobby
booby
chubby
cubby
derby       
verify that the output makes sense

Further examinations of large files: (/etc/passwd): piping tail to head, cutting

command/output explanation
$wc /homes/ddailey/public_html/aesop
   1726   12224   65713 public_html/aesop
$ae=/homes/ddailey/public_html/aesop
[ddailey]$tail -5 $ae
down into the well. But the Fox immediately [...]
his foot on her long horns managed to jump [...]
"Good-bye, friend," said the Fox, "remember [...]
<P>"Never trust the advice of a man in difficulties."
<P></P></A></BODY></HTML>
$ $head -5 $ae

From The PaperLess Readers Club, 
Houston (713) 977-9505 (BBS)

            Voice/Fax (713) 977-1719
      
Let's look at another file available on marble:/homes/ddailey/public_html/aesop. We count lines and look at the beginning and end of the file.
$head -400 $ae|tail -5

Master Fox.  "That will do," said he.   [...]

exchange for your cheese I will give you a  [...]
 
Let's look at lines 396 through 400 (Note: I truncated the output a bit to get it to fit in the table. Observe also that every other line is blank)
$ echo $w
/homes/share/words-english
$ grep ^sea. $w |head -8
seabed
seaboard
seacoast
seafare
seafood
seagull
seahorse
seal
$ grep ^sea. $w |head -8|cut -da -f2
bed
bo
co
f
food
gull
horse
l         
slice a text file based on a delimiter
$ grep ^sea. $w |head -8| sed s/sea//
bed
board
coast
fare
food
gull
horse
l                   
A better way to do what was attempted above.