I was attempting to produce the file list by piping the output of a find
command.  See my previous email for the problem I'm having with that...

I guess the question I would have is how you are producing the list in
"myfiles"?

in my case I suppose I could go to the directory that has the glog.log files
and say I wanted to replace bob with charlie I could do this on the command
line without needing to cat a file with a list of the files I wanted to
modify:

#perl -p -i.bak -w -e 's/bob/charlie/g' glog.log*

This is straight from the book "Learning Perl" pg. 231

If nobody can tell me why, when I redirect the standard output stream of the
find command into my program, I lose the first argument, then I guess I'll
have to do the same thing you did with cat...

It sounds like we are both trying to produce something a little more robust
that could be used in a variety of situations without having to create a new
input file every time.

-----Original Message-----
From: Richard Fernandez [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 31, 2003 4:01 PM
To: [EMAIL PROTECTED]
Subject: Replacing a string in a bunch of files


I just had a situation where I needed to replace one string with another
string in 200 files.
This is what I came up with, but I know there has to be a better way. Below
is my code.

"myfiles" contains a list of the files I need to scrub, one per line.

-------8<-----------------8<-----------------------
#!/usr/local/bin/perl -w
use strict;
$|++;


my @files = `cat myfiles` or die;
for (@files) {

        chomp;
        push @ARGV, $_;
}


$^I = ".bak";   # Got this from a previous message; thanks Peter!
while (<>) {

        s#/u01/app/webMethodsFCS#/u02/app/webMethodsFCSclone#g;
        print;

}
---------8<------------------8<-----------------------

Seems to me there should be a way to provide the filenames on the command
line
w/o having to read the list into an array first, but I tried using xargs
(this is unix) and a couple
of other things but couldn't figure it out.

Thanks for the help!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to