Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am greping a string from multiple files, but the one undesired side effect, is the filename prefacing the output. How can I suppress the filename outputs using only grep?

  $ grep -i lp lpNet* 
    lpNet:This was printed via the internet using the lp command.
    lpNet:I believe lp doesnt care what the device is. 
    lpNet1:This was printed via the internet using the lp command.
    lpNet1:I believe lp doesnt care what the device is. 
    lpNet2:This was printed via the internet using the lp command.
    lpNet2:I believe lp doesnt care what the device is. 
    lpNet3:This was printed via the internet using the lp command.
    lpNet3:I believe lp doesnt care what the device is. 

I have solved the issue for now using cat lpNet* | grep lp I am just wondering if there is a more efficient path to have the same effect

share|improve this question

1 Answer 1

up vote 7 down vote accepted

The default behavior is to print the filename when given multiple file arguments - to suppress this, you can add the -h or --no-filename option

From the Output Line Prefix Control section of the grep manual page:

   -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.
share|improve this answer

Your Answer

 
discard

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.