省略grep中的文件名


18

我正在从多个文件中提取一个字符串,但是一个不希望有的副作用是文件名在输出之前添加了前缀。如何仅使用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. 

我已经使用cat lpNet *解决了该问题。grep lp我只是想知道是否有更有效的途径来达到相同的效果

Answers:


31

默认行为是在给定多个文件参数时打印文件名-若要取消显示,可以添加-h或--no-filename选项

Output Line Prefix Control在grep手册页的部分中:

   -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.
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.