[3ae31e9] | 1 | grep searches a file for a given pattern. Execute by:
|
---|
| 2 |
|
---|
| 3 | grep [flags] regular_expression file_list
|
---|
| 4 |
|
---|
| 5 | Flags are single characters preceeded by '-':
|
---|
| 6 | -c Only a count of matching lines is printed
|
---|
| 7 | -f Print file name for matching lines switch, see below
|
---|
| 8 | -n Each line is preceeded by its line number
|
---|
| 9 | -v Only print non-matching lines
|
---|
| 10 |
|
---|
| 11 | The file_list is a list of files.
|
---|
| 12 | The file name is normally printed if there is a file given.
|
---|
| 13 | The -f flag reverses this action.
|
---|
| 14 |
|
---|
| 15 | The regular_expression defines the pattern to search for. Upper- and
|
---|
| 16 | lower-case are always ignored. Blank lines never match. The expression
|
---|
| 17 | should be quoted to prevent file-name translation.
|
---|
| 18 |
|
---|
| 19 | x An ordinary character (not mentioned below) matches that character.
|
---|
| 20 |
|
---|
| 21 | '\' The backslash quotes any character. e.g. "\$" matches a dollar-sign.
|
---|
| 22 |
|
---|
| 23 | '^' A circumflex at the beginning of an expression matches the
|
---|
| 24 | beginning of a line.
|
---|
| 25 |
|
---|
| 26 | '$' A dollar-sign at the end of an expression matches the end of a line.
|
---|
| 27 |
|
---|
| 28 | '.' A period matches any character except "new-line".
|
---|
| 29 |
|
---|
| 30 | ':a' A colon matches a class of characters described by the following
|
---|
| 31 | ':d' character. ":a" matches any alphabetic, ":d" matches digits,
|
---|
| 32 | ':n' ":n" matches alphanumerics, ": " matches spaces, tabs, and
|
---|
| 33 | ': ' other control characters, such as new-line.
|
---|
| 34 |
|
---|
| 35 | '*' An expression followed by an asterisk matches zero or more
|
---|
| 36 | occurrances of that expression: "fo*" matches "f", "fo", "foo", etc.
|
---|
| 37 |
|
---|
| 38 | '+' An expression followed by a plus sign matches one or more
|
---|
| 39 | occurrances of that expression: "fo+" matches "fo", etc.
|
---|
| 40 |
|
---|
| 41 | '-' An expression followed by a minus sign optionally matches
|
---|
| 42 | the expression.
|
---|
| 43 |
|
---|
| 44 | '[]' A string enclosed in square brackets matches any character in
|
---|
| 45 | that string, but no others. If the first character in the
|
---|
| 46 | string is a circumflex, the expression matches any character
|
---|
| 47 | except "new-line" and the characters in the string. For
|
---|
| 48 | example, "[xyz]" matches "xx" and "zyx", while "[^xyz]"
|
---|
| 49 | matches "abc" but not "axb". A range of characters may be
|
---|
| 50 | specified by two characters separated by "-". Note that,
|
---|
| 51 | [a-z] matches alphabetics, while [z-a] never matches.
|
---|
| 52 |
|
---|
| 53 | The concatenation of regular expressions is a regular expression.
|
---|