El Thursday 14 August 2008 17:30:43 [EMAIL PROTECTED] va escriure:
> Xavier,
>
> Thanks for the tip but can you help me by pasting the code too?  It
> might take 2 mins for you but I will have to fiddle with it longer :(
>
> Regards.
>
> On Aug 14, 6:02 am, [EMAIL PROTECTED] (Xavier Mas) wrote:
> > El Wednesday 13 August 2008 22:44:11 [EMAIL PROTECTED] va escriure:
> > > Hi,
> > >
> > > I am trying to search & replace a string in a file using the below
> > > perl command on unix.
> > >
> > > perl -pi -e 's/OLD/NEW/g' repltest.txt
> > >
> > > But I want the above command to display what lines were replaced.  Is
> > > it possible using some switch options?  If it is not possible using
> > > any of the switches, I don't mind couple of lines of code.
> > >
> > > unix version: SunOS 5.9 Generic_122300-22 sun4u sparc SUNW,Netra-T12
> > >
> > > Thanks in advance.
> >
> > you can use an if statement with binding operator (=~) to find out which
> > lines are going to be replaced.
> >
> > --
> > Xavier Mas
> >
> > ______________________________________________
> > LLama Gratis a cualquier PC del Mundo.
> > Llamadas a fijos y móviles desde 1 céntimo por
> > minuto.http://es.voice.yahoo.com

I guess this is what you need:

while(<FILE_IN>) {

        if (/OLD/) {
        print FILE_MATCHEDLINES "$_\n";
        s/OLD/NEW/;
        }

}

-- 
Xavier Mas


______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com


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


Reply via email to