Hi Preethi

Can you try.......

perl -pi.bak -e 's/(ab=test1.*?dc=test3)/ab=chk1,bc=chk2/sg' filename


[untested]

Thanks
Prasanna

-----Original Message-----
From: Preethi [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 22, 2006 3:21 PM
To: Dr.Ruud
Cc: beginners@perl.org
Subject: Re: Urgent :search and replace

Hi Ruud,

Thanks for the input. I will take care of your inputs next time I post
the
message.

The below solution did not work for me . My file runs almost to 1GB .
All I
have the string mentioned below.
I even tried the following option

perl -pi.bak -0777 -e 's/ab=test1, db=test2,dc=test3/ab=chk1,bc=chk2/gi'
filename.

But  it did not work. I also tried using -m. It failed.

Please let me know if there any other solution for this.

Thanks,
Preethi



On 6/22/06, Dr.Ruud <[EMAIL PROTECTED]> wrote:
>
> Preethi schreef:
>
>
> Never put "Urgent" in the Subject. Never address "us" as Experts. Just
> explain your problem.
>
> Subject: search and replace on broken lines
>
>
> > I have wired problem , I have search and replace string in very huge
> > text file . The problem with the string is broken in the differenet
> > line.
> >
> > I'm having a  string 'ab=test1, db=test2,dc=test3' and I want to
> > replace this with 'ab=chk1,bc=chk2'.
> > This string in the file is present in various fasion like
> > <File>
> > .........................ab=tes
> > t1, db=test2,dc=test3'....
> > ............................, ab=
> > test1,db=test2,dc=test3' .
> > ..................................
>
> What is "very huge"? Multiple GB?
>
> If the file is "only" a few MB, consider slurping it in:
>
> perl -i.bak -wpe '
> { local $/;
>    s/a\n?
>      b\n?
>      =\n?
>      t\n?
>      e\n?
>      s\n?
>      t\n?
>      1\n?
>      ,\n?
>     \ \n?
>      d\n?
>      b\n?
>      =\n?
>      t\n?
>      e\n?
>      s\n?
>      t\n?
>      2\n?
>      ,\n?
>      d\n?
>      c\n?
>      =\n?
>      t\n?
>      e\n?
>      s\n?
>      t\n?
>      3\n?
>      /ab=chk1,bc=chk2/xgi
> }
> ' filename
>
> (untested)
>
> The "local $/" sets the input record separator to undef. See perlvar.
> The inserted \n? are optional newlines.
>
>
> Your sample shows a
> ", db"
> and a
> ",db"
> so you'll need to adjust the regular expression above.
>
>
> Handy:
>
> perl -le '
> $s = q{ab=test1, db=test2,dc=test3} ;
> $r = join( q{\n}, split( q{}, $s ), undef) ;
> print qr/$r/
> '
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to