在 grep 中省略文件名

j0h*_*j0h 31 command-line bash grep cat

我正在从多个文件中提取一个字符串,但一个不希望的副作用是输出前的文件名。如何仅使用 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. 
Run Code Online (Sandbox Code Playgroud)

我现在使用 cat lpNet* 解决了这个问题 | grep lp 我只是想知道是否有更有效的途径来达到同样的效果

ste*_*ver 48

默认行为是在给定多个文件参数时打印文件名 - 要禁止此操作,您可以添加-h或 --no-filename 选项

Output Line Prefix Controlgrep 手册页的部分:

   -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.
Run Code Online (Sandbox Code Playgroud)