[OS X TeX] Search and replace in many files

Peter Dyballa Peter_Dyballa at Web.DE
Thu Sep 6 16:13:20 EDT 2012


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…

--
Greetings

  Pete

Isn't vi that text editor with two modes... one that beeps and one that corrupts your file?
				– Dan Jacobson, on comp.os.linux.advocacy




More information about the MacOSX-TeX mailing list