GREP and Regular Expressions

Week 10 Exercise – GREP and Regular Expressions

Value: 5 marks, marked out of 5
Due: End of Class, Week 10

AssignmentTutorOnline

Obtain the file grepdata.txt. , then upload it to your home directory

Once you have the file, write a series of grep statements that do the following. Save the statements as a script named in the folllowing form:\

lastname_firstname_grep1.sh

and upload it into SLATE.

  1. Print all lines that contain a phone number with an extension (the letter x or X followed by four digits).
  2. Print all lines that begin with three digits followed by a blank. Your answer must use the \ and \ repetition specifier.
  3. Print all lines that contain a date. Hint: this is a very simple pattern. It does not have to work for any year before 2000.
  4. Print all lines containing a vowel (a, e, i, o, or u) followed by a single character followed by the same vowel again. Thus, it will find “eve” or “adam” but not “vera”. Hint: \( and \)
  5. Print all lines that do not begin with a capital S.

Write grep statements that use command-line options along with the pattern to do the following:

  1. Print all lines that contain CA in either uppercase or lowercase.
  2. Print all lines that contain an email address (they have an @ in them), preceded by the line number.
  3. Print all lines that do not contain the word Sep. (including the period).
  4. Print all lines that contain the word de as a whole word.

Your patterns should work in any generic file of this sort. They should not be dependent upon the data in this particular file; if I add more lines of the same form to the file, your patterns should still work.