omit filenames in grep

40,244

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:
40,244

Related videos on Youtube

j0h
Author by

j0h

been using Linux since 2005. Ubuntu since whenever edgy eft was new. Lucid Lynx Ubuntu was the best Ubuntu I have ever used.

Updated on September 18, 2022

Comments

  • j0h
    j0h over 1 year

    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