search / replace in a text file
search / replace in a text file
- Subject: search / replace in a text file
- From: Jason Toews <email@hidden>
- Date: Mon, 12 Feb 2001 09:49:20 -0800
Some of you may recognize this question; I've posted it at other times on
the MacScript list. Still haven't found a perfect solution, so I'm still
searching.
I've got a gaggle of PostScript (or EPS) files. Within the text of those
files, there's one line that I need to edit (Specifically the "%%Title:"
line. It's easy enough to read the first chunk of the file, find the offset
of that line, throw the offending text into a variable, then do some
manipulation on it. At that point, I can write that chunk of text back into
the file... BUT: The text I'm writing to the file needs to have exactly the
same number of characters as the existing text to be replaced. Otherwise,
good text gets overwritten. My interim solution: Simply make sure that my
"corrected" text has fewer characters than the "bad" text, and fill up the
remainder with "%" symbols. This works, to be sure, but it's clunky.
What I WANT to do: Simply do a direct search and replace on the text IN the
file. I realize that I could script BBEdit to do this, but I'd rather not
involve another app opening and closing each one of these files. Isn't
there some OSAX that could do this? Yes, there are a ton of "Search and
Replace" OSAX out there. But typically, these require you to read the text
into a variable prior to manipulation, which is exactly the problem I'm
having...
Oh, and don't even suggest the "split the file into (1)the text BEFORE the
line to be changed, (2)the line to be changed, and (3)the text AFTER the
line to be changed" thing. These files are bloody huge. Too big to read
everything AFTER the offending line into a variable.
Hopefully, I've explained this well enough. Thanks in advance for any
advice you have to offer!
JASON P. TOEWS
Publishing System Analyst UAP Seattle, WA
1-800-642-2429 x3066 ~ pager 888-992-5855