6. Pattern MatchingContents:
A number of Unix text-processing utilities let you search for, and in some cases change, text patterns rather than fixed strings. These utilities include the editing programs ed , ex , vi , and sed , the awk programming language, and the commands grep and egrep . Text patterns (formally called regular expressions) contain normal characters mixed with special characters (called metacharacters). This chapter presents the following topics:
For more information on regular expressions, see Mastering Regular Expressions , listed in the Bibliography. 6.1 Filenames Versus PatternsMetacharacters used in pattern matching are different from metacharacters used for filename expansion (see Chapter 4, The Bourne Shell and Korn Shell , and Chapter 5, The C Shell ). When you issue a command on the command line, special characters are seen first by the shell, then by the program; therefore, unquoted metacharacters are interpreted by the shell for filename expansion. The command: $ could, for example, be transformed by the shell into: $ and would then try to find the pattern Array.c in files Bug.c , Comp.c , chap1 , and chap2 . To bypass the shell and pass the special characters to grep , use quotes: $ Double quotes suffice in most cases, but single quotes are the safest bet. Note also that in pattern matching, |
|