Reputation: 276
My instructions are the following:
find . -iname "*.[file extension]" -exec grep -H "[Searched string]" {} \;
find . -iname "*.[file extension]" -exec grep -in "[Searched string]" {} \;
As you can see, one is to list the file names that contain such string, the other one is to display the very line where it finds.
Both works perfectly separately but I know there is a way to combine them, it doesn't matter if the output is in two lines, it would work fine for me too, just can't find out how to do it.
Thanks in advance and I apologize if it's actually an answered question.
Upvotes: 1
Views: 209
Reputation: 1014
Just combine the grep options:
find . -iname "*.[file extension]" -exec grep -Hin "[Searched string]" {} \;
That will show the filename:lineno followed by the matching line.
Upvotes: 2