Date: Tue, 5 Mar 2002 11:36:41 -0500
Reply-To: Robert Virgile <virgile@MEDIAONE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Robert Virgile <virgile@MEDIAONE.NET>
Subject: Re: Replacing a string in a file
Content-Type: text/plain; charset="iso-8859-1"
Maybe using recfm=N takes care of these issues ... I'm not familiar with it.
Two changes to consider:
1. Add the truncover option to the infile statement:
infile 'c:\temp\temp.txt' recfm=N truncover;
If the incoming line contains fewer than 100 characters, the input statement
will take whatever is there.
2. Hold the line with a trailing @ sign, so later iterations of the input
statement read from the same line:
input chunk $char100. @;
Other infile statement options may help. One such option (I forget its
name) measures the length of the incoming data line. Another (lrecl=) may
be needed to access long incoming records.
Like I said, I'm not familiar with recfm=N and its implications, but any of
the above tools may come into play.
From: David L. Ward <dward@SASHELP.COM>
To: SAS-L@LISTSERV.UGA.EDU <SAS-L@LISTSERV.UGA.EDU>
Date: Tuesday, March 05, 2002 10:49 AM
Subject: Replacing a string in a file
>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.
>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
>but I'm sure they will be obvious to most of you.
> length chunk $200;
> infile 'c:\temp\temp.txt' recfm=N;
> file 'c:\temp\temp2.txt' recfm=N;
> input chunk $char100.;
> put chunk $char100.;
>Thanks for any help!