complex search and replaces (was Re: [OS X TeX] Support for AppleScript please)

Roger Hart rhart at
Mon Dec 6 19:01:49 EST 2004

I concur that the best way to script complex search/replaces is with 
perl.  I might suggest the following,

perl -i.old -p -e 's/original/replacement/g; 
s/original2/replacement2/g; s/original3/replacement3/g' filename.tex

Here -i.old instructs perl to make a backup of the original file, 
filename.tex.old, and to save the changes under the original filename 
(instead of writing the changes to STDOUT in the Terminal window).  And 
you can script a series of perl commands in this manner as one command.

I hope this helps,


On Dec 6, 2004, at 12:32 PM, Alan Curtis wrote:

> You could try a perl one-liner in a Terminal window. For example
> perl -p -e 's/original/replacement/g' *.tex
> would replace all occurrences of 'original' with 'replacement' in all 
> the files *.tex. The find and replace strings can be regular 
> expressions and so this can be very powerful.

Roger Hart
Assistant Professor, Departments of History and Asian Studies
University of Texas at Austin

office: Room 405, Garrison Hall
office phone: 512-475-7258
department fax: 512-475-7222
email: rhart at


--------------------- Info ---------------------
Mac-TeX Website:
           & FAQ:
List Post: <mailto:MacOSX-TeX at>

More information about the MacOSX-TeX mailing list