On May 12, 2013, at 21:24, Dean Avanti <
in...@avantivitastudios.com> wrote:
> Textwrangler does find and replace for single words, but how about lists of words. Lets say I wanted to translate words in a webpage, I dont want to do one at a time, I want to batch replace words.
______________________________________________________________________
Hey Dean,
This is a job for a sed or Perl text filter. You can do it with Applescript, but it will be a bit slow and more cumbersome to write and maintain.
------------------------------------------------------------------------------------------
#! /usr/bin/env perl
use strict; use warnings;
#---------------------------
while (<>) {
s!hello!ciao!gi;
s!goodbye!arrivederci!gi;
s!red!rosso!gi;
s!car!perch!gi;
s!van!van!gi;
s!holiday!vacanza!gi;
print;
}
------------------------------------------------------------------------------------------
#! /usr/bin/env bash
sed '
s!hello!ciao!g
s!goodbye!arrivederci!g
s!red!rosso!g
s!car!perch!g
s!van!van!g
s!holiday!vacanza!g
'
------------------------------------------------------------------------------------------
In both script the 'g' flag stands for global (not just the first instance).
In the Perl script the 'i' flag stands for case-insensitive, and you may want to remove it and do case-sensitive substitution to properly deal with capitalization like so:
s!hello!ciao!g
s!Hello!Ciao!g
Text filters should be installed here:
~/Application Support/TextWrangler/Text Filters/
You run them from the menu {Text}-->{Apply Text Filter}-->{Filter Name}
--
Best Regards,
Chris