On 6 March 2010 14:42, Amos Shapira <[email protected]> wrote:
> On 6 March 2010 13:23, Rick Welykochy <[email protected]> wrote:
>> Try this:
>>
>> #/bin/bash
>>
>> cp "$2" TestResult
>>
>> export IFS=','
>> cat Mapping/$1-Mapping | while read replace search
>> do
>>        perl -i -p -e "s/\Q$search/$replace/g" TestResult
>> done
>
> 12 points for this answer :). That's the proper way to do it.

Actually - if it's a one-off thing and the input is not large (or lots
of files) then it's good enough.

Otherwise if you are going to do it many times and care about performance then:

1. Do the entire read loop in perl.
2. Assign the "match" and "replace" strings into a hash.
3. Build a perl regexp: (\Qmatch1\E|\Qmatch2\E|...)
4. use it with something like s/$regexp/$hash{$1}/ge

Sorry not time for details but will try to get back with a working
example later if required.

Cheers,

--Amos
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to