LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2000, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 28 Jun 2000 11:32:14 -0700
Reply-To:     kmself@IX.NETCOM.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         kmself@IX.NETCOM.COM
Subject:      Re: UltraEdit "Replace in Files"
Comments: To: Ray Pass <raypass@worldnet.att.net>
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;
protocol="application/pgp-signature";

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 do # 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 done

...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? > > Ray > > > 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: raypass@att.net | > *------------------------------------------------* > > ------------------------------

-- Karsten M. Self <kmself@ix.netcom.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


[application/pgp-signature]


Back to: Top of message | Previous page | Main SAS-L page