Sortix cross-volatile manual
This manual documents Sortix cross-volatile. You can instead view this document in the latest official manual.
NAME
grep — search text with regular expression patternsSYNOPSIS
| grep | [-abcEFGhHiIlLnoqrRsTvxzZ] [-A lines-after] [-B lines-before] [-C lines-around] [-e pattern] [-f pattern-file] [-m max-count] [--binary-files=[binary|text|without-match]] [--color[=[always|auto|never]]] [--group-separator=separator] [--label=label] [--line-buffered] [--no-group-separator] [--no-ignore-case] pattern [file ...] |
DESCRIPTION
grep reads lines of text from the standard input and writes the lines that match the basic regular expression pattern to the standard output. If files are specified, the input is the files read separately in sequential order. The file path can be set to ‘-’ to specify the standard input.- -a
- Treat all input lines as text, even if they contain binary data that is not validly encoded printable text.
- -A lines-after, --after-context=lines-after
- Include lines-after lines of context after each match.
- -b, --byte-offset
- Include the byte offset of the matching line in the output line preamble.
- -B lines-before, --before-context=lines-before
- Include lines-before lines of context before each match.
- --binary-files=[binary|text|without-match]
- Select how to handle matches inside binary data. binary outputs matches inside text only, but issues a message for matches inside binary data. text outputs matches even inside binary text and is equivalent to -a. without-match outputs matches inside text only and is equivalent to -I. The default behavior is binary.
- -c, --count
- Output the number of matching lines instead of which lines matched.
- -C lines-around, --context=lines-around
- Include lines-around lines of context before and after each match. This option is equivalent to setting both the -A and -B options.
- --color[=[always|auto|never]]
- Color the output using terminal escape sequences if the standard output is a terminal. The parameter can be set to always (always color the output regardless of the standard output device) , auto (color the output only if the standard output is a terminal) , never (never color the output). The parameter is optional and defaults to auto. The color setting is set to auto by default in this implementation. This implementation can be faster without colors because it does not need to process input lines multiple times to color multiple matches per line.
- -e pattern
-
Select input lines matching this regular expression pattern. The syntax is selected per the -EFG options.Input lines match if they match at least one pattern from the multiple -e and -f options. If -e is used, then the otherwise mandatory pattern operand does not exist.
- -E, --extended-regexp
- Use the POSIX Extended Regular Expression ere(7) syntax for the patterns. This option is heavily encouraged because it is actually a regular expression language, it can be implemented much more efficiently, and it has much fewer surprising special cases. This option overrides the -FG options.
- -f pattern-file
-
Read additional patterns from the pattern-file, one pattern per line.Input lines match if they match at least one pattern from the multiple -e and -f options. If -f is used, then the otherwise mandatory pattern operand does not exist.
- -F, --fixed-strings
- The pattern is a string literal and matches if it is a substring of the input lines. This option combines well with the -x option to match the entire line. This option overrides the -EG options.
- -G, --basic-regexp
-
Use the POSIX Basic Regular Expression bre(7) syntax for the patterns. This syntax is discouraged because it is not a regular expression language. In particular, it is not required to portably support the alternation feature, and it is required to support back references (which cannot be implemented efficiently, requiring a worse implementation). It is recommended to use -E instead for non-trivial patterns.This implementation does not support back references, but as a non-portable extension, it does allow using extended regular expression features by preceding the ‘|’, ‘+’, ‘?’, and ‘{’ characters with a backslash.This syntax is the default syntax. This option overrides the -EF options.
- --group-separator=separator
- Whenever the -ABC options are used to include context lines around matching lines, separate each such non-adjacent group with this separator on its own output line. The default is ‘--’. This option overrides the --no-group-separator option.
- -h, --no-filename
- Never include the input path in the preamble. This option overrides -HrR.
- -H, --with-filename
- Always include the input path in the preamble. This option overrides -h.
- -i, --ignore-case
- Compare input lines against the patterns in a case insensitive manner per the locale rules. This option overrides --no-ignore-case.
- -I
- Never match lines inside binary data.
- -l, --files-with-matches
- Output only the paths of the input files that contain matching lines.
- -L, --files-without-match
- Output only the paths of the input files that do not contain matching lines.
- --label=label
- Use this label as the path of the standard input. The default label is ‘(standard input)’.
- --line-buffered
- Flush the standard output after each output line. This option overrides the standard behavior of only using line buffered semantics if the standard output is a terminal, otherwise fully buffered semantics are used by default, and matches will only be output if the buffer is full, or when the program terminates.
- -m max-count
- Read at most max-count matching lines from each input file. If max-count is at least one and any of the -ABC options are used as well, then the standard input is seeked back to the end of the last matching line, even though following context lines were output.
- -n, --line-number
- Include the input file line number in the preamble.
- --no-group-separator
- Do not separate non-adjacent groups with an output line controlled by the --group-separator option. This option overrides the --group-separator option.
- --no-ignore-case
- Compare input lines against the patterns in a case sensitive manner. This option overrides -i.
- -o, --only-matching
- Output only the exact matches inside each line. The non-matching parts of the input lines are omitted.
- -q, --quiet
- Do not output anything and only communicate the result via the exit status. If any matching line is found, then exit 0, even if an error occurs.
- -r, --recursive
- Recursively search any specified directories without following symbolic links. If no files are specified, then recursively search the working directory. This option overrides -R.
- -R, --dereference-recursive
- Recursively search any specified directories while following symbolic links. If no files are specified, then recursively search the working directory. This option overrides -r. This implementation will not detect infinite symbolic link loops in the filesystem.
- -s, --no-messages
- Do not error on input files and directories that could not be opened. All other errors remain.
- -T, --initial-tab
- Ensure the line data is aligned on a tab stop boundary.
- -v, --invert-match
- Match only lines that do not match any of the patterns.
- -x, --line-regexp
- Match only lines if any pattern matched the entire line, instead of the default substring logic.
- -z, --null-data
- Input lines are separated with a nul byte instead of the default line feed new line byte.
- -Z, --null
- Use a nul byte instead of ‘:’ and ‘-’ after the input file path in the preamble.
IMPLEMENTATION NOTES
This implementation is largely compatible with GNU grep, but has mild semantic differences and absent features. GNU grep is packaged and is available as ggrep(1) if needed.ENVIRONMENT
- LANG
- The default locale for locale variables that are unset or null.
- LC_ALL
- Overrides all the other locale variables if set.
- LC_COLLATE
- Compare the input lines to the patterns according to this locale's collating rules.