Sorry, my bad.  Forgot the -e switch...

perl -pi.bak -e 's|ReplaceThis|WithThis|' *

Rob

-----Original Message-----
From: Hanson, Rob 
Sent: Monday, January 19, 2004 8:04 PM
To: 'Perl'; [EMAIL PROTECTED]
Subject: RE: Search and replace pattern in a file


I think you will like this, it does exactly whay you described...

perl -pi.bak 's|ReplaceThis|WithThis|' *

This does everything you want, AND makes a backup of each file.  You can
only perform a substitution on a single line though (AFAIK).

See perldoc perlrun for all of the details.

WARNING: Make an extra backup of the files before doing this! It is easy to
make a mistake and delete everything by accident.

Rob

-----Original Message-----
From: Perl [mailto:[EMAIL PROTECTED]
Sent: Monday, January 19, 2004 6:48 PM
To: [EMAIL PROTECTED]
Subject: Search and replace pattern in a file


Hi,
  here is the situation i have :

i have a long list of files in a directory. i have to
search and replace a particular pattern in each file.
since a file cannot be read and written to at the same
time, what's the best way of doing the search and
replace ?
i take this approach of doing the search and replace
and then writing the contents into a new temporary
file. then i close both the files. thereafter i write
the contents of  the temporary file into the original
file.

i am sure, there is a better efficient way of doing
it.
can anybody let me know.


__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

-- 
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>


-- 
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