Hi,
Thanks for the reply
No,  it is not very elegant and no, I'm not concerned about that - I just
need it to run through once, it is part of a bigger script that creates sql
queries and temporary tables.
part of the table it is reading from is:

ADD_NARRATION_19  ,ADD_NARATION_19 
ADD_NARRATION_20  ,ADD_NARATION_20 
CLAIM_VALUE       ,CLAIM_VALUE      
INVOICE__035      ,INVOICE_$   
This is in a csv file.

the end result gives something like:

"SELECT  ADD_NARRATION_19, ADD_NARRATION_19, ADD_NARRATION_20,
ADD_NARRATION_20 
CLAIM_VALUE, CLAIM_VALUE, INVOICE__035  FROM G110 WHERE.... 
                                                          
 
Regards, Mehmet


> Hi Mehmet,
> 
> A sample input file would help a little.  My first guess is there are no
> quotes around the $field:
> 
>     grep -w "$field"
> 
> Also it's not the most elegant script - which you may not care about :)
> 
> Nima
> 
> On Sat, Mar 6, 2010 at 8:45 PM, Mehmet Yousouf <
> [email protected]> wrote:
> 
> > Hi,
> > I'm having trouble with the following search and replace script:
> >
> > #!/bin/bash
> > # two parameters are passed in, a mapping file and the text file to
replace
> > in
> >
> > for fields in $(cat ./Mapping/$1-Mapping |awk 'BEGIN{FS=","}{print $2}')
> > do
> >  searchstring= $fields
> >  replacestring="`grep -w $fields ./Mapping/$1-Mapping |awk
> > 'BEGIN{FS=","}{print $1}'`"
> >  sed -e "s/$searchstring, / $replacestring, /g" $2 >TestResult
> > done
> >
> >  it fails if there is a $ sign in the variable $field e.g. amount_$ .
How
> > can I get grep to "behave" the way I want?
> > Any help would be appreciated.
> >
> > Regards, Mehmet
> >
> >
> >
> > --
> > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
> >
> 
> 
> 
> -- 
> http://me.nima.id.au/
Hi Mehmet,

A sample input file would help a little.  My first guess is there are no quotes around the $field:

    grep -w "$field"

Also it's not the most elegant script - which you may not care about :)

Nima

On Sat, Mar 6, 2010 at 8:45 PM, Mehmet Yousouf <[email protected]> wrote:
Hi,
I'm having trouble with the following search and replace script:

#!/bin/bash
# two parameters are passed in, a mapping file and the text file to replace
in

for fields in $(cat ./Mapping/$1-Mapping |awk 'BEGIN{FS=","}{print $2}')
do
 searchstring= $fields
 replacestring="`grep -w $fields ./Mapping/$1-Mapping |awk
'BEGIN{FS=","}{print $1}'`"
 sed -e "s/$searchstring, / $replacestring, /g" $2 >TestResult
done

 it fails if there is a $ sign in the variable $field e.g. amount_$ . How
can I get grep to "behave" the way I want?
Any help would be appreciated.

Regards, Mehmet



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



--
http://me.nima.id.au/
-- 
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