Chapter 14 ExercisesRead Chapter 14 of the Unix text and work on the Unix system. Make sure you can answer the following questions:Chapter 14 Regular Expressions (grep, egrep, sed, vi, etc.)(pages 618-645) 14-1. What are the advantages of using grep instead of using an editor for a simple searching job? 14-2. Why is the first argument to grep almost always enclosed in single quotes? 14-3. What is fgrep? What is egrep? 14-4. In the following imaginary grep command line: grep abc def ghi jkl abc is interpreted by the utility grep as a(n) _____________ def is interpreted by the utility grep as a(n) _____________ ghi is interpreted by the utility grep as a(n) _____________ jkl is interpreted by the utility grep as a(n) _____________ [Page 621] 14-5 Explain what the difference is between the following command lines (try them!):
14-6. In the command line: grep '[Tt]he' ~/*
14-7. Explain how the regular expression metacharacters in each of the following patterns work when seen by grep. What do the patterns match? ^.....
xx*$
[Tt]he
[bmBM]other
[0-9]A
[09]A
[0-9][0-9]
[A-Z][0-9][A-Z] *[0-9][A-Z][0-9] (matches postal codes!)
[^a-z]
[\^a-z]
[\^]
[^^]
^[^^] the first ^ means __________________
the second ^ means __________________
the third ^ means __________________
@[Aa]lgonqu*i*n[Cc]oll*ege *\. *c[ao]m*
14-8a. What pattern instructs grep to locate lines with a $ (dollar sign) at the beginning of the line? 14-8b. What pattern instructs grep to locate lines with a ^ (circumflex) at the end of a line? 14-8c. What pattern instructs grep to locate lines containing a real period (".")? 14-9. Do the Review 1 questions on page 634 of the text. Note: The metacharacters \< and \> (page 635) only work inside the vi editor on ACADAIX. 14-10a. What command line uses grep and the period (".") metacharacter to find all empty lines in a file? (An empty line is a line that has no characters on it.) 14-10b. What command line uses grep to find all blank or empty lines in a file? (In other words, find all lines containing only zero or more space characters.) 14-11. What command line uses a single egrep command to search for the text FREE or the text $00.00 in the file named costs? (Test this one! Make sure it doesn't find $00x00!) [p.643] 14-12.
Using the input file given on page 619, explain what will be displayed by: 14-13. Using the input file given on page 642, explain what
would be displayed by: 14-14. Do the Review 2 questions on page 644 of the text.
|
|
Web Author: Ian! D. Allen idallen@ncf.ca |