Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: (2) in-place edit, regex, one-liner (perl -i.bak -pe)

by chromatic (Archbishop)
on Nov 24, 2000 at 03:02 UTC ( #43175=note: print w/replies, xml ) Need Help??


in reply to Re: (2) in-place edit, regex, one-liner (perl -i.bak -pe)
in thread in-place edit, regex, one-liner

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.)

Replies are listed 'Best First'.
(code) Re: (4) in-place edit, regex, one-liner (Mo' Betta)
by ybiC (Prior) on Nov 24, 2000 at 03:52 UTC
    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")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://43175]
help
Chatterbox?
[Corion]: Discipulus: I think Module::Corelist ( or corelist ) can tell you that
[Corion]: Meh - Module::CoreList
[choroba]: Just use List::Util 1.29
[choroba]: Be kind to people using old Perl with newer version of the module
[Corion]: But why not simply specify 'List::Util' => 1.29 in your prerequisites? People might install a more recent version of the module into their Perl
[Corion]: (what choroba said)
[Discipulus]: ah! simpler and cleaner
[Discipulus]: thanks! use List::Util 1.29 qw(pairmap ... just works!

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2017-05-25 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?