Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

in-place edit, regex, one-liner

by ybiC (Prior)
on Nov 24, 2000 at 01:20 UTC ( #43168=perlquestion: print w/ replies, xml ) Need Help??
ybiC has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to replace all instances of img src="image.gif" with img src="/Images/image.gif" in about 100 HTML documents.   Below is what I've come up with, which creates the .bak file properly, but leaves a zero-byte edited file.   What am I overlooking?

perl -i.bak -n -e 's/img src=\"image\.gif\"/img src=\"\/Images\/image\.gif\"/g' file.html

    cheers,
    Don
    striving for Perl Adept
    (it's pronounced "why-bick")

Comment on in-place edit, regex, one-liner
Re: in-place edit, regex, one-liner
by mdillon (Priest) on Nov 24, 2000 at 01:22 UTC
    you're using '-ne', but not printing anything at the end of the evaluated code. try '-pe' or add a 'print;' to the end of your code, as appropriate.
      Woo-hoo!   -pe instead of -ne did the trick!   Thanks a bunch, mdillon.

      perl -i.bak -pe 's/img src=\"image\.gif\"/img src=\"\/Images\/image\.gif\"/g' file.html

      Here's that syntax sans toothpicks:
      perl -i.bak -pe 's///g' *.html

          cheers,
          Don
          striving for Perl Adept
          (it's pronounced "why-bick")

        I think you can cut that down a bit.

        perl -pe -i.bak 's!(img  src=")(image\.gif")!$1/Images/$2!g' *.html

        (I haven't tested it, but I think it's okay.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-07-01 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls