Re: modifying files using script



sunitajain@xxxxxxxxx wrote:

I had a huge number of files in which I had to search and replace a
specific string with another one.
I wrote the following script for it:

#!/bin/csh
set lsfile=`ls *.txt`
foreach f ($lsfile)
set strgrep=`grep -l $ORIGINAL $f`
if ($strgrep == $f) then
/bin/vi $f <<viCommands
:%s/$ORIGINAL/$NEWSTR/g
^[
:wq
viCommands
endif
end
This script works well for one file but exits after that.
I expect it to loop through for all the files.
Can anyone help me out with this?

perl -i -pe's/\Q$ENV{ORIGINAL}\E/$ENV{NEWSTR}/g' *.txt


John
--
use Perl;
program
fulfillment
.