next up previous
Next: Regular expressions on sequences Up: Regular Expressions, Profiles and Previous: Regular Expressions, Profiles and

UNIX Regular Expressions

  1. Copy the following into a file called grepfile:

     
    dg
    dog
    doog
    dogg
    dogggg
    doooggg
    the dog
    the dogs
    dog dog
    


  2. At your unix prompt, type

    % grep 'dog'

    Observe that nothing happens. This is because grep is waiting for the other half of its input. Type ctrl-c. Observe that you get your prompt back.

  3. At your unix prompt, type

    % grep 'dog' grepfile

    Observe what happens. Before proceeding, some notes on grep and regular expressions:



  4. Now work out a regular expression to use that will make grep return only the line containing just the word dog. Test it by typing

    % grep 'xxx' grepfile

    with your regular expression instead of 'xxx'

    hint: Remember those anchors ^ and $

  5. Now work out a regular expression for egrep that will make grep return only the lines "dog" and "doog".

next up previous
Next: Regular expressions on sequences Up: Regular Expressions, Profiles and Previous: Regular Expressions, Profiles and
David Ardell 2005-01-31