[OS X TeX] Search and replace in many files
Alain Schremmer
schremmer.alain at gmail.com
Fri Sep 7 18:23:28 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?
>
>
> 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.
>
> 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…
TextWrangler did each search-and-replace (900 files) in a few
seconds. It was all over in less than 5 minutes.
I am still near speechless.
Best regards to all.
--schremmer
More information about the MacOSX-TeX
mailing list