grep without showing path/file:line
你是如何grep并且只返回匹配行的?即,结果中省略了路径/文件名。
在这种情况下,我希望查找当前目录中的所有.bar文件,搜索术语foo
1 | find . -name '*.bar' -exec grep -Hn FOO {} \; |
无需
1 | grep -hn FOO /your/path/*.bar |
其中,
-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.
请注意,您正在使用
-H, --with-filename
Print the file name for each match. This is the default when there is
more than one file to search.
用
1 | find . -name '*.bar' -exec grep -hn FOO {} \; |
从手册页:
1 2 3 | -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. |