Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to output the line containing a certain pattern located in specifically named files in a unstructured directory hirearchy. Each file I'm interested in is named "foo.xml". The pattern I'm interested looks like: <digit><digit>T<digit><digit> (as a PERL regex: \d\dT\d\d). I want to output the entire line that matches this pattern (even the extra stuff on that line that doesn't match the pattern).

Where I'm at:

find . | grep foo.xml executed in the "root" gives me a list of the files I'd want to scan.

What do I do from here?

I'd much rather do this at the commandline. I could easily write a PERL script but there's probably a really straight forward way to do this.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You could try something like:

find . -name foo.xml -exec grep REGEX '{}' \;

edit In your case the REGEX is

'[0-9][0-9]T[0-9][0-9]'
share|improve this answer
    
so the -exec option to find executes any subsequent expressions, where '{}' is replaced by any found matches to the find command, and the command to execute is terminated by '\;'. –  jmetz Jul 23 '12 at 18:35
    
works like a champ, thanks –  jglouie Jul 23 '12 at 18:47

Alternatively, since you mentioned PERL, you can use grep's -perl-regexp option:

find . -name foo.xml -exec grep -P '\d\dT\d\d' '{}' \;

Lovely feature if you are used to perl regexes.

share|improve this answer
    
thanks - very helpful :) –  jglouie Aug 28 '12 at 15:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.