7 January 2022

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.

  1. Match any lower-case letter
  2. Match any upper-case letter
  3. Match any alphanumeric characgter
  4. Match any whitespace character (add to the list)
  5. Match any character that is not a digit
  6. Match a, e, i, o, u, and y

Use oneTwo.txt to check your result. We will pool our solutions here.

  1. [a-z]
  2. [A-Z]
  3. [0-9a-zA-Z]
  4. \s
  5. [^0-9], \D
  6. [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 ...

  1. Count the number of words containing x, y, or z
  2. Count the number of lines in the system dictionary containing no regular vowel (aeiou)
  3. List all lines in the system dictionary containing the string "yzy"
  4. Count all lines in the system dictionary containing three or more 'z's.
  5. List all words in ending with 'gry'
  6. List all seven-letter words that have vowels in their first, third, fifth, and seventh letters.
  7. List all words that present with z, y, and x, in that order.
  8. Count all words contiaining the strings 'ing' and 'ity.'
  9. Do any of these words in the last prblem end in 'ity'? If so, tell the first one alphabetically.
  10. 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.
  1. grep -E '[xyz]' hughJass.txt > test.txt
    wc -l test.txt
    201230
    Also
    grep -E '[xyz]' /usr/share/dict/words | wc -w
  2. grep -iE '^[^aeiou]*$' hughJass.txt | wc -l
  3. grep -E 'yzy' hughJass.txt | wc -l
    grep yzy hughJass.txt | wc -l
  4. grep -iE 'z[a-z]*z[a-z]*z' /usr/share/dict/words | wc -w
    grep -iE 'z.*z.*z' /usr/share/dict/words | wc -w
  5. grep -E 'gry$' hughJass.txt
  6. grep -iE '^[aeiou].[aeiou].[aeiou].[aeiou]$' hughJass.txt |wc -l
  7. grep -iE 'z.*y.*x.*' hughJass.txt
  8. grep -i ity hughJass.txt | grep -i ing
  9. grep -i ity hughJass.txt | grep -i ing | grep -iE 'ity$' | head -1
  10. grep -E '^x.*y$' hughJass.txt | tr [:lower:] [:upper:]

Orring

rower

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)[!.]?$

Earn your tIArA


Remove all instances of the letter e.

cat someFile | tr -d e

Remove all instances of the letter E, case insensitive

cat someFile | tr -d Ed

Remove all alphabetical characters.

cat someFile | tr -d [:alpha:]
cat someFile | tr -d [a-zA-z]


Now get rid of all of the spaces left bhind

cat someFile | tr -d [a-zA-Z] | tr -d ' '

Replace all digits with X.




Caesar cipher

5

a - f
b - g
c - h
.
.



u  - z
v - a
w - b
x - c
y - d
z - e


Encode:

tr  "[a-z]" "[f-za-e]"

Decode:





The sed manual