
我正在查找文件中的一些文本,但三個文件很多,並且搜索的文本在一個文件中出現多次,我如何接收包含搜索文本的文件列表,並且每個文件僅列出一次?
答案1
grep -l xyz file*
其中 xyz 是搜尋模式,file* 是要搜尋的檔案列表
答案2
grep -l LIST PATTERN
是要走的路。或者,可以用來xargs
做同樣的事情:
xargs grep "My Search Pattern" < input.txt
xargs
當您想要使用grep
從管道傳遞的多個檔案名稱時特別有用,例如:
find ~/Documents ~/bin -print0 | xargs -0 grep 'Search Term'