# 2014 Jan 17 # Lecture 6 # Annotated history # Show the symbolic link of the dictionary file on klaatu (your Linux distro may have it in a different location) 1 ls -l /usr/share/dict # Show the contents of the file pointed to by the symbolic link (linux.words) 2 more /usr/share/dict/words # Perform the word count (wc) command on the file to show that it contains quite a number of entries 3 wc /usr/share/dict/words # Show the contents of the current working directory to show that words is not there 4 ls -l # Use the ln command to create a link (pointer) to the dictionary file to use as a convenient shortcut 5 ln -s /usr/share/dict/words words # Show the contents of the current working directory again to show the new entry, words # (may show in a different color to indicate that it is a link) 6 ls -l # Perform the word count (wc) command on the (linked) file, words 7 wc words # Use grep to find an exact match to this text (can have anything else in front of or behind it) 8 grep loofah words # Use grep to find an exact match to this text (can have anything else in front of or behind it) 9 grep twig words # Use grep to find an exact match to this text (can have anything else in front of or behind it) 10 grep 'twig' words # Now use the special characters ^ and $ to anchor the pattern to the front and end of the line 11 grep '^twig$' words # Now use the special character ^ to anchor the pattern to the front of the line 12 grep '^twig' words # Now use the special character $ to anchor the pattern to the end of the line 13 grep 'twig$' words # Find words that start with the letters q and u (can be lower or uppercase) 14 grep '^[Qq][Uu]' words # How many of those words are there? 15 grep '^[Qq][Uu]' words | wc # Find words that start with the letter q (can be lower or uppercase), but NOT followed by a u or U # Pay attention to whether ^ is inside or outside of [ ] 16 grep '^[Qq][^Uu]' words # There are a lot fewer of q without u words (useful to know in Scrabble) 17 grep '^[Qq][^Uu]' words | wc # Find words that start with lowercase q, have at least one letter following q, and ending in ing, with anything in-between 18 grep '^q.*ing$' words # Use escaped parentheses \( \) to surround a pattern # Anchor pattern at the beginning and end of the line (^ and $ special characters) # Match the first part of the pattern again \1, so things like aa, dodo, hiphip, and so on are matched 19 grep '^\([a-z]*\)\1$' words