grep -rin searchstring * | cut -d: -f1-2
This will searchstring search recursively (for the searchstring string in this example), ignoring case, and displaying line numbers. The output of this grep will look something like this:
/path/to/result/file.name:100: Line in file where 'searchstring' is found.
Then we pass this result to the cut command, using a colon : as a field separator and displaying fields 1 through 2.
When I don't need line numbers, I often use -f1 (only the file name and path), and then direct the output to uniq , so that I see each file name only once:
grep -ir searchstring * | cut -d: -f1 | uniq
JBW Jul 19 '12 at 17:55 2012-07-19 17:55
source share