Date: Tue, 5 Mar 2002 10:41:17 -0500
Reply-To: "David L. Ward" <dward@SASHELP.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Ward" <dward@SASHELP.COM>
Subject: Replacing a string in a file
Content-Type: text/plain; charset="iso-8859-1"
Hi all, before I spend too much time on this, what is the best way to
replace all occurrences of a string with another in a binary file? Assume
we want v6 compatibility (200 char string limit). The complication that
arises is that if you read the binary file in 200 character chunks, the
boundary of your chunks may occur in the middle of the search string. Plus,
if your chunk is comprised of too many search strings, the replacements (if
longer than the search strings) may make the length of the string longer
than 200 characters.
The file needs to be binary so don't assume I can solve this by doing
line-based reading and writing. I'm trying to replace strings in a variety
of file formats, PCL, RTF (which can be line based, I know, but I'd rather
stick with an exact copy of the file just with the replacements), etc.
Besides, binary data is like reading one LONG line.
This is the blind-man's approach. There are many problems I won't point out
but I'm sure they will be obvious to most of you.
data _null_;
length chunk $200;
infile 'c:\temp\temp.txt' recfm=N;
file 'c:\temp\temp2.txt' recfm=N;
input chunk $char100.;
chunk=tranwrd(chunk,'Default','Replacement');
put chunk $char100.;
run;
Thanks for any help!
David W
|