Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

find the xml files

by Anonymous Monk
on Sep 14, 2009 at 11:39 UTC ( [id://795094] : perlquestion . print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How to combine the below code together.
find . -type f -name "*.xml" -print -exec grep -i '<book></book>' {} \ +; find . -type f -name ".xml" -print -exec grep -i "<name=>*.*Sydney*.*" + {} \;
How to list the XML files, which has the line
<book></book> and <name> which has the word "Sydney"

Replies are listed 'Best First'.
Re: find the xml files
by marto (Cardinal) on Sep 14, 2009 at 12:13 UTC
      If you are looking for a Perl solution see File::Find::Rule

      The File-Find-Rule-XPath module is even designed for exactly this type of search.

Re: find the xml files
by Utilitarian (Vicar) on Sep 14, 2009 at 12:15 UTC
    grep -i "<name=>*.*Sydney*.*" $(find . -type f -name "*.xml" -print -e +xec grep -i '<book></book>' {} \;)
    use the $(command) in bash
      On executing the command I got message like this -bash: /bin/grep: Argument list too long

        Probably because you have too many XML files that contain <book></book>. Look into xargs, or the - option for grep.

        $ find /path -name '*.xml' -exec grep 'pattern1' {} /dev/null \; | cut -d: -f1 | grep 'pattern2' -

         

        print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
        Well that's probably because the argument list is too long ;)
        You can write a simple bash loop to get around this;
        for i in $(find . -type f -name "*.xml" -print -exec grep -i '<book></ +book>' {} \;);do grep -i "<name=>*.*Sydney*.*" $i && echo $i;done