Student name: ______________________________________
ULI101 Section: _______________
This quiz is worth 2.5% of your course grade.
Maximum time allowed is 20 minutes.
See the sample test file
Instructions:
Provide grep commands according to the following criteria, working with a file called
'input'. With the exception of question #12, all questions are worth 2 marks.
1. Display all lines that are exactly 5 characters long:
grep “^.....$” input more elegant way to find a line of ‘n’ characters is grep –E “^.{n}$” input or
grep “^.\{n\}$” input (Must ‘escape’ { and } with \) or use egrep instead of grep –E
2. Display all lines that have at least one letter 'o' in them, upper- or lower-case:
grep –i “o” input or grep “[oO]” input
3. Display all lines with string 'or' followed by an 'ate' anywhere after that:
grep “or.*ate” input
4. Show all lines that do not start with a lower-case letter:
grep “^[^a-z]” input grep –v “^[a-z]” will show blank lines as well
5. Display all lines that do not have two letters 'r' following each other:
grep –v “rr” input
6. Count all blank lines:
grep –c “^$” input
7. Show all lines that end with a comma followed by a single digit:
grep “,[0-9]$” input
8. Show all lines that contain an asterisk (*):
grep “\*” input
9. Display lines that contain a phone number (for example: 647-555-1234):
grep –E “[0-9]{3}-[0-9]{3}-[0-9]{4}” input (if you use grep without –E you will have to ‘escape’ {} like in Q1)
10. (3 marks) Show lines containing numbers with a decimal point (for ex.: 23.123):
NOW, THIS ONE IS TOUGH AS YOU HAVE TO USE EITHER –E OPTION OR egrep. You gathered that {n} means
a repetition of n times. If you put {n,m} it means it repeats a minimum of ‘n’ and the maximum of ‘m’
times. Finally, and that is what we have to use here to find any decimal number (Michal does not specify
the format), {n, } means that it repeats a