Thanks both of you.
When I try while read replace search < Mapping/$1-Mapping
the loop keeps fetching the first record and does not step through the
mapping file.
I am now using:
cp $2 TestSed
export IFS=', '
cat Mapping/$1-Mapping1 | while read replace search
do
if [ $search != $replace ];
then
echo $replace $search
perl -i -p -e "s/\Q$search/$replace/g" TestSed
fi
done
The conditional fixes the issue with the perl replace command not ending on
the last line.
I'm quite happy with the end result, thanks. It would be nice to know why
that line does not work though....
Just to fill you in:
This script is called from a script that does preparatory work and calls
other scripts then finishes the queries
up to a certain point - to get the menial work out of the way.
I wanted the "jobs" separate so that I could use them standalone if required
at a later date.
Thanks again - Regards, Mehmet
> ----- Original Message -----
> Subject: Re: [SLUG] Search and replace question
> From: Amos Shapira <[email protected]>
> To: "Rick Welykochy" <[email protected]>
> CC: "SLUG" <[email protected]>
> Date: 06-03-2010 13:46
>
>
> 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.
>
> One thing that makes me cringe a bit whenever I see it is "cat
> single-file |", replace it with an input redirection:
>
> while read replace search < Mapping/$1-Mapping
> ...
>
> --Amos
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html