1 Regular Expressions, Grep and Unix

  1. Read http://www.uccs.edu/~ahitchco/grep/
  2. Log on to igor (or any other Unix system) and type:
    grep -E "^a...d$" /usr/share/dict/words
    

    Describe the output.

  3. type
    cat  /usr/share/dict/words
    

  4. type
    cat  /usr/share/dict/words |wc -l
    

  5. How many words are there that start with a and end with k? What are they?

  6. use grep to find the following:
    1. All the words that start with 'A' or 'a' and end with a 'c' and have at least one 'b' somewhere in between.
    2. All the words that start with 'A' or ('a' followed by zero or more 'b's and end with a 'c' and have at least one 'b' somewhere in between.
    3. Find all the words with all five vowels a,e,i,o,u occurring in order.
    4. Find all the words that do not have any vowels.
    5. Find all the filenames on the system that contain your username. Use the 'locate' comand.
    6. Find all the words that end with 'and'.
    7. Find all the words that contain an 'a' and a 'b'.
    8. Find all the words that contain exactly one 'a' and exactly one 'b'.

  7. Write a Hope function which checks whether a list is a palindrome.

  8. Write a Hope function which takes a list of lists and returns the ones which are palindromes.

s.danicic@gold.ac.uk
Sebastian Danicic BSc MSc PhD (Reader in Computer Science)
Dept of Computing, Goldsmiths, University of London, London SE14 6NW
Last updated 2011-03-15