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

Roger Hart rhart at mail.utexas.edu
Tue Dec 7 01:01:49 CET 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,

Roger


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 mail.utexas.edu
http://uts.cc.utexas.edu/~rhart

*********************************

--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
           & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>





More information about the macostex-archives mailing list