I'm looking some text in files , but three are a lot of files and searched text appears several times in one file, how can I receive a list of files that contains searched text with every file listed only once?

2 Answers 2

grep -l xyz file*

where xyz is the search pattern , and file* is the list of files to be searched in


grep -l LIST PATTERN is the way to go. Alternatively one could use xargs to do the same thing:

xargs grep "My Search Pattern"  < input.txt 

xargs is particularly useful when you would want to use grep on several filenames passed from a pipe, for instance:

find ~/Documents ~/bin -print0 | xargs -0 grep 'Search Term'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .