[OS X TeX] Search and replace in many files
Alain Schremmer
schremmer.alain at gmail.com
Thu Sep 6 21:48:30 EDT 2012
On Sep 6, 2012, at 4:13 PM, Peter Dyballa wrote:
>
> Am 06.09.2012 um 01:14 schrieb Alain Schremmer:
>
>> Here are the four search and replace that I need to make and that
>> the Ogrekit does very nicely:
>>
>> =========================
>> 1 Search string: (Copy full line)
>>
>> \ifthenelse{\boolean{Quiz?}}%
>>
>> Replace string: (Copy two full lines)
>>
>> %SSSSSSSSSSSS
>> \ifthenelse{\boolean{Quiz?}}%
>>
>>
>> =========================
>> =========================
>> 3 Search string: (Copy two full lines)
>>
>> %SSSSSSSSSSSS
>> \ifthenelse{\boolean{Quiz?}}%
>>
>> Replace string: (Copy all full lines)
>>
>> %SSSSSSSSSSSS
>> \ifthenelse{\boolean{Workout?}}%
>> {%begin Workout? true
>> %ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
>> - Begin WORKOUT
>> \UseProblem{\CheckableItem-w}%
>> {%
>> WORKOUTtext%
>> }{%
>> $a$%
>> }{%
>> $b$%
>> }{%
>> $c$%
>> }{%
>> $d$%
>> }{%
>> x%
>> }{%
>> WORKOUTdiscussion%
>> }%
>> %ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
>> - End WORKOUT
>> }%end Workout? true
>> {%begin Workout? false
>> \ifthenelse{\boolean{Quiz?}}%
>>
>>
>> =========================
>
> If I read that correctly, then case #1 should turn into the
> replacement text of case #3, yes?
No. These are not 4 cases but four search-and-replace that I have to
do in that order on each form. A look at September 3 post will show
you better what I have to do.
> When OgreKit works so nice, then why don't you perform the
> substitutions that way? Open all the TEX files which need the
> changes in TeXShop (this can be done from Finder by selecting them
> and then using Ctrl-click to choose "Open with" and then selecting
> TeXShop as application to handle them). Apply the first text
> substitution in the first file – and save it! Then proceed to next
> TEX file and repeat the same text substitution – the OgreKit has
> saved the substitution, didn't it? So just fire it up once more!
> Save the file and proceed with next one. With n (tres)passes you
> repetitively update n times m files.
That is exactly what I did when I said I was doing them by hand. But
we are talking over 1800 files in 36 folders!!!!
These "forms" are all strictly identical so that, were they blank, I
would just do the search and replace in one, duplicate the modified
form 50 times, use Applescript to remove "copy", put them in a folder
and make 35 copies of that folder, remove "copy" from their names.
Done deed.
What is happening here is that these forms are filled with data. I
could transfer the data in the modified forms produced as above but
THAT would surely have to be done by hand and would be even more work.
> Your text substitutions are a bit too complicated for specialised
> programmes like sed or maybe Perl. Text editors like vi or GNU Emacs
> could be used too…
I fervently hope that TextWrangler's multiple files search and replace
will do it: it seems able to handle carriage returns which sed won't
do. I will know for sure tomorrow.
Best regards
--schremmer
More information about the MacOSX-TeX
mailing list