Next: , Previous: , Up: Command-line Options   [Contents][Index]


2.1.4 Output Line Prefix Control

When several prefix fields are to be output, the order is always file name, line number, and byte offset, regardless of the order in which these options were specified.

-b
--byte-offset

Print the 0-based byte offset within the input file before each line of output. If -o (--only-matching) is specified, print the offset of the matching part itself.

-H
--with-filename

Print the file name for each match. This is the default when there is more than one file to search.

-h
--no-filename

Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search.

--label=LABEL

Display input actually coming from standard input as input coming from file LABEL. This can be useful for commands that transform a file’s contents before searching; e.g.:

gzip -cd foo.gz | grep --label=foo -H 'some pattern'
-n
--line-number

Prefix each line of output with the 1-based line number within its input file. (-n is specified by POSIX.)

-T
--initial-tab

Make sure that the first character of actual line content lies on a tab stop, so that the alignment of tabs looks normal. This is useful with options that prefix their output to the actual content: -H, -n, and -b. This may also prepend spaces to output line numbers and byte offsets so that lines from a single file all start at the same column.

-Z
--null

Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name. For example, ‘grep -lZ’ outputs a zero byte after each file name instead of the usual newline. This option makes the output unambiguous, even in the presence of file names containing unusual characters like newlines. This option can be used with commands like ‘find -print0’, ‘perl -0’, ‘sort -z’, and ‘xargs -0’ to process arbitrary file names, even those that contain newline characters.


Next: , Previous: , Up: Command-line Options   [Contents][Index]