| command &output/verification | explanation |
| $w=/home/SRUNET/david.dailey/words ~$echo $w /home/SRUNET/david.dailey/words |
Defining the variable $w to point to a string which happens to name a file. |
| $grep ottle $w bluebottle bottle bottleneck mottled pottle throttle |
Look for lines in $w containing the string "ottle". What is a string? |
| grep ottle $w|wc 6 6 53 |
How many words in $w are there that contain "ottle" |
| $grep ottl $w|wc 6 6 53 |
Demonstrating that the words containing "ottl" all happen to contain "ottle" |
| grep ott $w|wc 76 76 651 |
However, there are 76 words that contain "ott". This implies there are 70 that contain "ott" in which the "ott" is not followed by "l" or "le" |
| $grep o $w|wc 16062 16062 160364 ~$wc $w 35916 35916 332173 /home/SRUNET/david.dailey/words |
About half of the lines in $w contain the letter 'o' at least once. |
| $grep -v o $w|wc 19854 19854 171809 $expr 16062 + 19854 35916 |
Finding (and then counting) the words (lines) that do not contain 'o' within $w. Note that the number 35916 is partitioned, by this into two sets. |
| ~$grep a $w|wc 19360 19360 189459 ~$grep -v i $w|wc 16780 16780 137652 ~$grep i $w|wc 19136 19136 194521 |
Playing with other characters |
| ~$grep -v s $w|wc 21884 21884 192638 |
Here are those that do not contain 's' |
| $grep -v s $w|head a aardvark aback abaft abalienate abalienation abandon abandoned abandonment abate $grep s $w|head abacus abase abased abasement abash abashed abbess abdominous abiogenesis abjectness |
Here are some that do or do not contain 's'. Note use of piping to head to examine the beginning of the stream |
| $grep ott
$w|grep -v ottl|wc 70 70 598 ~$grep ott $w|grep -v ottl|head begotten besotted blotter blotto bog-trotter bottom bottomless boycott calotte clotted |
Examining some of the 70 words that contain "ott", but not "ottl" |
| Redirecting and appending into a file | |
| $echo happy ever
after>temp $wc temp 1 3 17 temp $echo in the marketplace>temp $wc temp 1 3 19 temp |
This demonstrates that the phrase "happy ever after" has two fewer characters than "in the marketplace". |
| $echo happy ever
after>temp $wc temp 1 3 17 temp |
Here, the content of temp is restored to its initial state, containing just "happy ever after": 14 letters, two spaces, and a carriage return. |
| $echo in the
marketplace>>temp $wc temp 2 6 36 temp |
Here, we use the append operator ('>>')
to take the output from echo and append it after the existing contents
of temp. Note that [1 3 19] [1 3 17] + [2 6 36] |
| $cat temp happy ever after in the marketplace |
This verifies that, indeed, the contents of temp are now equal to the concatenation of the two strings. |
| grep -o to show (or count) particular
instances of a match |
|
| $cat temp happy ever after in the marketplace $grep e temp happy ever after in the marketplace |
A file in which each of the two lines contain the letter 'e' at least once. Grep finds all lines which match the regular expression 'e' |
| $grep f temp happy ever after $grep x temp $ |
The file has one line containing an 'f' and no lines containing 'x' |
| $grep -o e temp
e e e e e e |
This shows all actual occurrences of 'e' in the file temp. |
| $grep -o e
temp|wc 6 6 12 |
This counts the e's in temp. |
| $grep -o .[aeiou] temp ha e ve a te he ma ke la ce |
This shows the vowels (lowercase) in the context of the preceding character. |