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

William F. Adams wadams at atlis.com
Tue Dec 7 09:01:07 EST 2004


> 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.

On Dec 6, 2004, at 7:01 PM, Roger Hart wrote:

> 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,

I've got two books on Perl at home, but they're just not ``clicking'' 
with me.

I guess I should try harder --- did manage some success with awk (using 
it to increment page numbers for an index).

The big thing with bkreplacem is it's a graphical tool which will 
manage search and replace sets, so it appeals to the visual side of me.

William

-- 
William Adams, publishing specialist
voice - 717-731-6707 | Fax - 717-731-6708
www.atlis.com

--------------------- 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 MacOSX-TeX mailing list