Help to find string and return following characters from list of files

Hi,

I'm fairly new to UNIX, but hopefully some-one can help me with this:

I am using the following code to find files with the name "example.xml":

 
find . -name "example.xml" -print

that would print me a list like the example here:

./dir1/dir2/example.xml
./dira/dirb/example.xml

now here's the riddle for you guys; I want to be able to search in each file returned for the string "Version" and return the following x amount of characters or just that line where the pattern is matched if that is easier.

Hope you can help! :eek:

Leighton

find . -name "example.xml" -exec grep Version {} \;
1 Like

Try this to print filename and line containing string "Version"

find . -name example.xml -exec awk '/Version/{print FILENAME,$0}' {} \;
1 Like
find . -name "example.xml" -exec grep Version {} /dev/null \;

or

find . -name "example.xml" -print | xargs grep Version
1 Like
find . -name "example.xml" 2>/dev/null -exec grep -l Version "{}" \;

Try this ^^, it will only print the filename, where the search string is being found.
If that works, try this command without "-l" argument, and it should be that what you're looking for, I hope :wink:

Best regards

1 Like

Thank you for the quick replies, I'll try this now and let you know!

---------- Post updated at 04:44 PM ---------- Previous update was at 04:36 PM ----------

Thank you all, many way to skin this cat it seems. They all do the job Thank you for expanding on the first reply as the filename in the output has proved very useful. :smiley: