http://www.perlmonks.org?node_id=43169


in reply to in-place edit, regex, one-liner

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.

Replies are listed 'Best First'.
Re: (2) in-place edit, regex, one-liner (perl -i.bak -pe)
by ybiC (Prior) on Nov 24, 2000 at 01:44 UTC
    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.)

        I like it, thanks chromatic.   May I throw a slight curve in the fairway?
        A quick dig in The Owl leads me to think something like this will match reference any image of alphanumeric name.   How close am I?

        perl -i.bak -pe 's!(img  src=")(\w+?\.(gif|jpg|jpeg|png)")!$1/Images/$2!g' *.html

        Update: The above one-liner was tweaked, and now works.

            Changes this:

        <img src="12345.gif"> <img src="1b3e5.jpg"> <img src="1B3Df.jpeg"> <img src="abcde.png">

            To this:
        <img src="/Images/12345.gif"> <img src="/Images/1b3e5.jpg"> <img src="/Images/1B3D5.jpeg"> <img src="/Images/abcde.png">
        And saves original files as ".bak".
            cheers,
            Don
            striving for Perl Adept
            (it's pronounced "why-bick")