Matching Control (GNU Grep 3.7)
Next: General Output Control, Previous: Generic Program Information, Up: Command-line Options [Contents][Index]
2.1.2 Matching Control
-e patterns¶
--regexp=patternsUse
patternsas one or more patterns; newlines withinpatternsseparate each pattern from the next. If this option is used multiple times or is combined with the-f(--file) option, search for all patterns given. Typicallypatternsshould be quoted whengrepis used in a shell command. (-eis specified by POSIX.)-f file¶
--file=fileObtain patterns from
file, one per line. If this option is used multiple times or is combined with the-e(--regexp) option, search for all patterns given. The empty file contains zero patterns, and therefore matches nothing. (-fis specified by POSIX.)-i¶
-y
--ignore-caseIgnore case distinctions in patterns and input data, so that characters that differ only in case match each other. Although this is straightforward when letters differ in case only via lowercase-uppercase pairs, the behavior is unspecified in other situations. For example, uppercase “S” has an unusual lowercase counterpart “ſ” (Unicode character U+017F, LATIN SMALL LETTER LONG S) in many locales, and it is unspecified whether this unusual character matches “S” or “s” even though uppercasing it yields “S”. Another example: the lowercase German letter “ß” (U+00DF, LATIN SMALL LETTER SHARP S) is normally capitalized as the two-character string “SS” but it does not match “SS”, and it might not match the uppercase letter “ẞ” (U+1E9E, LATIN CAPITAL LETTER SHARP S) even though lowercasing the latter yields the former.
-yis an obsolete synonym that is provided for compatibility. (-iis specified by POSIX.)--no-ignore-case¶Do not ignore case distinctions in patterns and input data. This is the default. This option is useful for passing to shell scripts that already use
-i, in order to cancel its effects because the two options override each other.-v¶
--invert-matchInvert the sense of matching, to select non-matching lines. (
-vis specified by POSIX.)-w¶
--word-regexpSelect only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word constituent characters are letters, digits, and the underscore. This option has no effect if
-xis also specified.Because the
-woption can match a substring that does not begin and end with word constituents, it differs from surrounding a regular expression with ‘\<’ and ‘\>’. For example, although ‘grep -w @’ matches a line containing only ‘@’, ‘grep '\<@\>'’ cannot match any line because ‘@’ is not a word constituent. See The Backslash Character and Special Expressions.-x¶
--line-regexpSelect only those matches that exactly match the whole line. For regular expression patterns, this is like parenthesizing each pattern and then surrounding it with ‘
^’ and ‘$’. (-xis specified by POSIX.)
Next: General Output Control, Previous: Generic Program Information, Up: Command-line Options [Contents][Index]