Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find a string in all files ending .xml and print file name 1

Status
Not open for further replies.

mendof

Technical User
Feb 22, 2010
2
CZ
Hi all,

I am struggling to get specific string in some files.
I am using


find . -iname "*.xml " -print -exec cat {} \; | grep -i "*string*"


and I can find string, but filenames I cannot see...
Any comment is welcome and thanks in advance

Regards,
mendof
 
Hi

If you not need to search recursively, then :
Code:
grep -i "*string*" *.xml
If you have to search in sub-directories too :
Code:
grep -ri "*string*" . | grep .xml:
But if you want to keep your [tt]find[/tt] & [tt]grep[/tt] combination "
Code:
find . -iname "*.xml" -exec grep -Hi "*string*" '{}' \;
Tested with GNU [tt]grep[/tt].

Feherke.
 
Hi,

thank you. Last option is one I wanted to use, as I want to search in many directories for .xml files and specific string in them.

Last option works, thanks a lot

Regards,
mendof
 
A more legacy way:
Code:
find . -name '*.xml' | xargs grep -i '*string*'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top