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>


Reply via email to