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
.



Relevant Pages

  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... You can set the working directory from within your Perl ... match for the "Citation:" etc string. ... The Perl Language and the Regular Expression Language are different ...
    (comp.lang.perl.misc)
  • my script crashes when I try to rename the file!
    ... OK, thanks, but the script does not seem to rename the files. ... You can set the working directory from within your Perl ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (perl.beginners)
  • Re: Perl script to extract data from webpage? (knucklehead newbie).
    ... Your $& is a special perl variable that represents the string matched by ... the last successful pattern match...which in the case of your example ... I have this running now using a script I found elsewhere, ...
    (comp.lang.perl)
  • Re: How to pass string in command line argument.
    ... Perl Pra wrote: ... i have perl script that searches given string (the string should be passed ... The string should be sent to the script with double quotes attached to it ...
    (perl.beginners)
  • Re: Sencha Touch--Support 2 browsers in just 228K!
    ... this particular script is so awful that anyone who could ... These functions are available on every String object. ... if (!dom) { ... @param o The object with the attributes ...
    (comp.lang.javascript)