[wplug] Find and Replace

David Ostroske eksortso at linuxmail.org
Fri Nov 15 21:58:19 EST 2002


That will work well. I would use the following, though:
find . -name '*.for' |perl -lpi~ -e 's#N=10#N=20#g'

This will change ALL Fortran source files in the directory tree, as well as make backups (with filenames ending in "~") of the files. 

I included "-l" out of force-of-habit. I typically use it when processing file lists; the command "perl -lne 'print unless -e' filelist.txt" will chomp off newlines, then print out filenames (with newlines) if the files don't exist. But in the example above, the -l switch wouldn't cause any harm.

--- David Ostroske
    eksortso at linuxmail.org


----- Original Message -----
From: Brian Medley <bpmedley at 4321.tv>
Date: Fri, 15 Nov 2002 07:59:45 -0500 
To: wplug at wplug.org
Subject: Re: [wplug] Find and Replace


> On Fri, Nov 15, 2002 at 05:27:13AM -0500, J Aaron Farr wrote:
> 
> > What I'm want is a simple script that will do a find and replace over a
> > number of files.  Specifically I've got a bunch of FORTRAN files and I
> > want to easily change a variable declaration like "N=10" to "N=20".  So
> > assuming I have all the files I want to change in my working directory,
> > then I should be able to run some command like:
> > 
> > replace.sh *.for
> 
> perl -pi -e 's#N=10#N=20#g' tiny.as
> 
> -- 
> ~'`^`'~=-.,__,.-=~'`^`'~=-.,__,.-=~'`^`'~=-., \|/  (___)  \|/ _,.-=~'`^`
>                           Brian Medley         @~./'O o`\.~@
> "Knowledge is Power" brian.medley at verizon.net /__( \___/ )__\  *PPPFFBT!*
>   -- Francis Bacon                               `\__`U_/'
>  _,.-=~'`^`'~=-.,__,.-=~'`^`'~=-.,__,.-=~'`^`'~= <____|'  ^^`'~=-.,__,.-=
> ~`'^`'~=-.,__,.-=~'`^`'~=-.,__,.-=~'`^`'~=-.,__,.-==--^'~=-.,__,.-=~'`^`
> _______________________________________________
> wplug mailing list
> wplug at wplug.org
> http://www.wplug.org/mailman/listinfo/wplug
> 
> 

-- 
______________________________________________
http://www.linuxmail.org/
Now with POP3/IMAP access for only US$19.95/yr

Powered by Outblaze



More information about the wplug mailing list