Date: Wed, 28 Jun 2000 11:32:14 -0700
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
Subject: Re: UltraEdit "Replace in Files"
In-Reply-To: <no.id>; from raypass@WORLDNET.ATT.NET on Wed, Jun 28,
2000 at 10:07:18AM -0400
Content-Type: multipart/signed; micalg=pgp-sha1;
Using Linux shell tools, bash/korn/posix shell script and shell tools.
These are available on Linux and Linux-like OSs, as well most pretenders
through compatibility kits such as Cygwin32, UWIN, MKS, and Microsoft's
rebranded Interix product.
for file in *.SAS
# Replace strings in file $file, output to a temporary file,
# move temporary to original if successful, else output error
# message to stderr.
sed -e '/original-pattern/s//replacement-string/g' < $file > \
$file.tmp && mv $file.tmp $file || \
echo "`basename $0`: error processing $file" 1>&2
...if the one-fell-swoop approach is too drastic for you, you can copy
the files to an archive before modifying them, or create a new working
set which you modify and test, then commmit.
Better yet, use file revision control such as RCS or CVS to manage your
changes -- including the ability to show what's changed between two
versions of a file.
On Wed, Jun 28, 2000 at 10:07:18AM -0400, Ray Pass wrote:
> Tom (original request below),
> Now that we know why you're getting the results you're getting, the
> question becomes, how do you get what you want? Here's one way, albeit a
> bit kludgy. Can anybody do better?
> 1) Note all the file extensions which would be undesirably included when
> looking for *.SAS, such as
> .SASv7bDAT, .SASv7bCAT. You can use Windows Explorer and sort by file type.
> 2) Temporarily rename all of these files so they will not have extensions
> starting with .SAS - like .XSASv7bDAT, .XSASv7bCAT for example. If there
> are only a few, do it by hand. If there are many, build a macro in SAS to
> do it. Have the macro execute operating system commands to first get all
> the file names in a string (DIR) and then step through the string
> incrementally to do the renaming.
> 3) Do the UltraEdit Replace in Files.
> 4) Change the temporarily renamed files back to their original names with a
> revised version of the macro you built in step 2), or by hand if there are
> not many.
> As I said, this is a bit kludgy, but it should work. I'll bet there's a
> much more elegant way out there. Anybody?
> Apologies if this seems off-topic, but I think it is important. Recently
> > I queried SAS-L about how to do a global "search & replace", covering an
> > entire directory. Several people steered me to UltraEdit, and its
> > "Replace in Files" capability. Well, I just tried to globally change a
> > text string in "*.SAS" datasets (i.e. my programs) ... but the process
> > seemed to be taking too long, so I aborted it. I then found that, in
> > addition to my SAS programs, UltraEdit was apparently going through ALL my
> > files, in the given directory, whose extension *began* with SAS, i.e. my
> > SAS v8 data and catalog files (*.SASv7bDAT, *.SASv7bCAT). This is
> > obviously undesired and extremely dangerous behavior! Did I miss an
> > option somewhere that would have restriced the search-and-replace to *.SAS
> > datasets alone? The version of UltraEdit I'm using is "UltraEdit-32
> > Professional Text/HEX Editor, Version 7.10a". Thanks,
> | Ray Pass, Ph.D. voice: (914) 693-5553 |
> | Ray Pass Consulting eFax: (914) 206-3780 |
> | 5 Sinclair Place |
> | Hartsdale, NY 10530 e-mail: firstname.lastname@example.org |
Karsten M. Self <email@example.com> http://www.netcom.com/~kmself
Evangelist, Opensales, Inc. http://www.opensales.org
What part of "Gestalt" don't you understand? Debian GNU/Linux rocks!
http://gestalt-system.sourceforge.net/ K5: http://www.kuro5hin.org
GPG fingerprint: F932 8B25 5FDD 2528 D595 DC61 3847 889F 55F2 B9B0