Testing out Character Classes
Download oneTwo.txt
;
it has lots of characters, each on its own line.
To see the matches for a character class, do this
unix> grep -E '(your character class)' oneTwo.txt
Feel free to add your favorites to the list.
- Match any lower-case letter
- Match any upper-case letter
- Match any alphanumeric characgter
- Match any whitespace character
(add to the list)
- Match any character that is not a digit
- Match a, e, i, o, u, and y
Use oneTwo.txt
to check your result.
We will pool our solutions here.
[a-z]
[A-Z]
[0-9a-zA-Z]
\s
[^0-9], \D
[aeiouy]
hughJass.txt
Resource A regex cheat sheet courtesy of Taco Bell
I have put the system dictionary of
cs.ncssm.edu
into this file, which you can
download if you are not working on the server.
You can count lines in a file by piping to
wc -l
Search the system dictionary and ...
- Count the number of words containing x, y, or z
- Count the number of lines in the system dictionary containing no regular vowel (aeiou)
- List all lines in the system dictionary containing the string "yzy"
- Count all lines in the system dictionary containing three or more 'z's.
- List all words in ending with 'gry'
- List all seven-letter words that have vowels in their first, third, fifth, and seventh letters.
- List all words that present with z, y, and x, in that order.
- Count all words contiaining the strings 'ing' and 'ity.'
- Do any of these words in the last prblem end in 'ity'? If so, tell the first one alphabetically.
- The filter
tr "[:lower:]" "[:upper:]"
will take input and uppercase it as output. List all words beginning with the letter x and ending with the letter y in upper-case.
grep -E '[xyz]' hughJass.txt > test.txt
wc -l test.txt
201230
Also
grep -E '[xyz]' /usr/share/dict/words | wc -wgrep -iE '^[^aeiou]*$' hughJass.txt | wc -l
grep -E 'yzy' hughJass.txt | wc -l
grep yzy hughJass.txt | wc -lgrep -iE 'z[a-z]*z[a-z]*z' /usr/share/dict/words | wc -w
grep -iE 'z.*z.*z' /usr/share/dict/words | wc -wgrep -E 'gry$' hughJass.txt
grep -iE '^[aeiou].[aeiou].[aeiou].[aeiou]$' hughJass.txt |wc -l
grep -iE 'z.*y.*x.*' hughJass.txt
grep -i ity hughJass.txt | grep -i ing
grep -i ity hughJass.txt | grep -i ing | grep -iE 'ity$' | head -1
grep -E '^x.*y$' hughJass.txt | tr [:lower:] [:upper:]
Orring
Photo credit: Ronni Kurtz
We want to match all of these as narrowly as possible.
Amy Sheck is bonkers John Morrison is nuts! Darrel Spells is gaga Amy Sheck is gaga. John Morrison is nuts. Darrel Spells is bonkers!
Eschew:
Joe Biden is nuts. Todd Roberts is gaga. Johh Morrison is psycho!
Amy Sheck/John Morrison/Darrel Spells, is, bonkers/nuts/gaga, ./!/
Too broad:
A member of NCSSSM's CS faculty; "is"; "gaga", "bonkers," "nuts," or "gaga"; ".," "!," or "\n"
A first name, last name, the word "is", an adjective, and an optional punctuation mark
random name + "is" + adj + punctuation
John Morrrison or Amy Sheck or Darrel Spells " is " crazy or bonkers or gaga possible . or !
^(John Morrison|Amy Sheck|Darrel Spells) is (crazy|gaga|nuts|bonkers)[!.]?$