Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for an explanation how grep --label=LABEL works: Maybe somebody can give me an example [or two] on what --label= is for.

I understand what grep and zgrep are supposed to do – the latter is mentioned in the entry on --label= in the info page:

... especially useful when implementing tools like `zgrep'

98% of what I found so far is copy/paste from info grep and the other two percents the command is embedded in a script which I don't understand.

share|improve this question
up vote 6 down vote accepted

This feature makes reading the output of grep easier. If you want to check data that grep cannot read directly then you may end up using a pipe to feed grep instead of creating a temporary file which grep can read. If you don't want a temporary file (e.g. because it would be huge) then without --label you would have the problem that grep cannot print the information in which file the match was found.


echo $'fubar\nbaz\nbat' | grep --label=inputfile -H a

is equivalent to

echo $'fubar\nbaz\nbat' > inputfile
grep -H a inputfile

Without --label the first approach would not work (i.e. not deliver the wanted output) so you would have to do something like this:

echo $'fubar\nbaz\nbat' | grep a | awk '{print "inputfile:" $0}'

But this does not offer match highlighting in the console.

share|improve this answer
Thank you very much for the answer - now it makes sense! May I just add, for others, that \n in the string stands for newline when using echo [I wasn't sure myself and this confused a bit]. – erch May 6 '13 at 18:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.