从 grep -r 输出中删除目录路径
Remove directory path from grep -r output
我是运行 grep -r 在多个文件中查找一个词的上下文
我使用 -r 递归地执行此操作,-i 忽略大小写,-C 获取下方和上方的行:
grep -r -i -C 10 --group-separator="==========" "29/04/2020" "$dir" >> output.txt
然而,在我的输出中,我得到了匹配之前的文件名,例如:
../data/filename1.txt- (other text)
../data/filename1.txt- 29/04/2020 is the date for etc
../data/filename1.txt- (other text)
==========
../data/different_filename.txt- (other text)
../data/different_filename.txt- something in 29/04/2020
../data/different_filename.txt- (other text)
我想作为输出:
(other text)
29/04/2020 is the date for etc
(other text)
==========
(other text)
something in 29/04/2020
(other text)
你知道我如何改变 grep -r 命令来排除文件路径吗?
使用grep -h
,如man 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.
我是运行 grep -r 在多个文件中查找一个词的上下文
我使用 -r 递归地执行此操作,-i 忽略大小写,-C 获取下方和上方的行:
grep -r -i -C 10 --group-separator="==========" "29/04/2020" "$dir" >> output.txt
然而,在我的输出中,我得到了匹配之前的文件名,例如:
../data/filename1.txt- (other text)
../data/filename1.txt- 29/04/2020 is the date for etc
../data/filename1.txt- (other text)
==========
../data/different_filename.txt- (other text)
../data/different_filename.txt- something in 29/04/2020
../data/different_filename.txt- (other text)
我想作为输出:
(other text)
29/04/2020 is the date for etc
(other text)
==========
(other text)
something in 29/04/2020
(other text)
你知道我如何改变 grep -r 命令来排除文件路径吗?
使用grep -h
,如man 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.