Re: modifying files using script
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Sat, 12 Aug 2006 23:07:32 GMT
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
.
- References:
- modifying files using script
- From: sunitajain@xxxxxxxxx
- modifying files using script
- Prev by Date: Re: How to rid man pages of reverse video junk?
- Next by Date: Getting the file name
- Previous by thread: Re: modifying files using script
- Next by thread: Re: modifying files using script
- Index(es):
Relevant Pages
|