Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
Patterns z/OS UNIX System Services User's Guide SA23-2279-00 |
|
The examples of grep, so far, have displayed the records in a file that contain the desired string anywhere in the line. If you want to be more specific—say to find records that begin with a certain string of characters (instead of having that string anywhere in the line)—use grep with patterns instead of strings. To understand patterns, it helps to think about the special wildcard
characters discussed in Using a wildcard character to specify file names. Remember that you
can use patterns in commands; for example:
removes
all files in the working directory that have the .txt extension.
Instead of specifying a single file name, this example uses the special
character * to represent any file name of the appropriate
form.In the same way, a grep pattern uses special characters
so that one pattern can represent many different strings.
Note: The special characters for grep patterns are not
the same as the characters used on command lines, and the mechanisms
involved are also different: however, patterns and wildcard
characters are conceptually similar.
Special characters used in a pattern are called pattern
characters, or metacharacters. Some pattern
characters are:
A typical grep command has the form:
This displays all the records in the file that match
the given pattern. For example:
displays
all the records that begin with the word Superman.
displays all the records that end in 00.If you want to use the literal meaning of a pattern character instead of its special meaning, put a backslash (\) in front of the character. Example: To find
all the lines that end in $1.00, issue:
Without a backslash in front of the $ and . (period), these characters would have their special
pattern meanings. |
Copyright IBM Corporation 1990, 2014
|