Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Multiline Search-Replace With Perl One-liner

Reply
Thread Tools

Multiline Search-Replace With Perl One-liner

 
 
cibalo
Guest
Posts: n/a
 
      01-12-2012
Hello,

I have migrated my free website to my linux web server recently. I
have to re-code all my htm files, of which they were created under
Windows.

I need to make a search and replace with Perl One-liner. I want to
search/replace backward slash to forward slash only in the relative
image path for all <img> tags, which may span over multiple lines.
So the <img> tag may like this:
<html>
<body>
<img src="public_html\images\Buster.jpg" height="250" width="128"
alt=" /\ See above"
title=" /\
See above" />
</body>
</html>

Sadly I haven't done RegEx searching in a while now. I'd be very
thankful for some help.

Thank you very much in advance!!!

Best Regards,
cibalo
 
Reply With Quote
 
 
 
 
cibalo
Guest
Posts: n/a
 
      01-14-2012
On Jan 12, 8:53*pm, Tad McClellan <(E-Mail Removed)> wrote:
> I will ignore the restriction.
> ---------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $html = '<html>
> <body>
> <img src="public_html\images\Buster.jpg" height="250" width="128"
> * alt=" * * */\ See above"
> * * title=" * * */\
> See above" />
> </body>
> </html>
> ';
>
> $html =~ s/src="([^"]+)"/ '"' . fix_slash($1) . '"'/ge;
>
> print $html;
>
> sub fix_slash {
> * * my($src) = @_;
> * * $src =~ tr!\\!/!;
> * * return $src;}
>
> ---------------------


Hello Tad McClellan,

Thank you very much for replying to my post. What I need is a working
solution, be it a one-liner or perl/sed/awk/bash script.

Your solution isn't that applicable to my case, becasue
1. I have many html files
2. All my html codings have to be included in your perl script.
3. Maybe your script can read my html files and modify the img src
path accordingly!

But Thank You Anyway!

Best Regards,
cibalo
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      01-14-2012
cibalo <(E-Mail Removed)> wrote:
>On Jan 12, 8:53*pm, Tad McClellan <(E-Mail Removed)> wrote:
>> I will ignore the restriction.
>> ---------------------
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>>
>> my $html = '<html>
>> <body>
>> <img src="public_html\images\Buster.jpg" height="250" width="128"
>> * alt=" * * */\ See above"
>> * * title=" * * */\
>> See above" />
>> </body>
>> </html>
>> ';
>>
>> $html =~ s/src="([^"]+)"/ '"' . fix_slash($1) . '"'/ge;
>>
>> print $html;
>>
>> sub fix_slash {
>> * * my($src) = @_;
>> * * $src =~ tr!\\!/!;
>> * * return $src;}
>>

>
>Thank you very much for replying to my post. What I need is a working
>solution,


That sounds like a job offer to me. This NG is not about job offers.

>Your solution isn't that applicable to my case, becasue
>1. I have many html files


Yes. So? Why does that make Ted's function inapplicable?

>2. All my html codings have to be included in your perl script.


How so? Ted's script suggested nothing of that sort.

>3. Maybe your script can read my html files and modify the img src
>path accordingly!


Guess what? Ted's script is self-contained such that anyone can run and
test the code as is without any further external data or modifications.
That is the most desireable way to post code because nobody else has
your files but you.
Did you even look at his code? Did you even understand the most basic
structure? Or are you really unable to identify the key element that
does all the work and copy-n-paste that piece into your own program?
If that is your problem, then indeed you may want to post a job offer,
but please do so it in a more appropriate NG.

>But Thank You Anyway!


Thank you for your consideration.

jue
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 02-03-2011 11:00 AM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
how to define a variable to hold a multiline text input in perl from html multiline textbox dale zhang Perl Misc 8 11-30-2004 06:53 AM
Perl multiline command syntax Nigel Perl Misc 6 05-13-2004 03:27 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments