On Wed, 2008-08-13 at 13:44 -0700, [EMAIL PROTECTED] wrote:
> 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.
> 
> 

If you just want the lines displayed, the following will do.  If you
want to record them, a little extra work is necessary.

  perl -pi -e 's/OLD/NEW/g&&print STDERR' repltest.txt

To record (nothing is displayed):

  perl -pi -e 's/OLD/NEW/g&&print STDERR' repltest.txt 2>lines_replaced.txt


-- 
Just my 0.00000002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."

"Perl is the duct tape of the Internet."
        Hassan Schroeder, Sun's first webmaster


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


Reply via email to