using a table to replace a value in a file

have a file that i would like to replace the value in the third position (file is comma separated) with a value in a table.  the value in the table begins with a "  and ends in a ".  the sed command to replace does not work.

numofrows=`wc -l tempfile.tmp`
 for i in $numofrows
    thirdvalue=$(awk -F"," '{print $3}' tempfile.tmp )
     eval tablename=\$table_${thirdvalue}
    sed 's/"$thirdvalue"/"$tablename"/g' < tempfile.tmp > newtempfile.tmp

table is this

at the beginning of the script i have this to determine the server and table to use.

hostname=`uname -n`
case $hostname
       servername ).      /temp/;;

Thanks in advance for the help
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Please post sample data for this file:
. . .have a file that i would like to replace the value in the third position (file is comma separated). . .
Also sample data for this table:
. . . with a value in a table. . . .
What do you mean by "determine the server and table to use"? Use for what?
bjeAuthor Commented:
If the server is a test server or prodution server the values in would be different.  the same script handles both test and production servers.

i use the word table for to indicate the values in this file are for lookup and replace purpose.

the file looks like this,

the looks like this,

if value3 in the file equals dog, then replace with the value with the information in  "bb=value12,cc=value13"

so the new file would be

Try something like this:
#Source table (replace.tmp):
cat - <<! >replace.tmp
#Target table (tempfile.tmp):
cat - <<! >tempfile.tmp
awk -F',' 'BEGIN{OFS=",";
        while ((getline line < "replace.tmp") > 0)
  for (y=1;y<=NF;y++) o[y]=$y;
  for (x=1;x<=n9;x++) {o3=substr(o[3],2,length(o[3])-2);
    if (o3 == v0[x,1]) o[3]=v0[x,2];}
  for (y=1;y<=NF;++y) printf "%s,",o[y];
  printf "\n"
}' tempfile.tmp > newtempfile.tmp
$ cat newtempfile.tmp

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

bjeAuthor Commented:
Thanks, will give this a try.

I am working on another task and using sed to replace values that are stored in a variable.

This is what i have,

sed 's/"$value1"/"$value2"/g' < filename.tmp > newfilename

is this correct?

no, try this:

sed "s=\"$value1\"=\"$value2\"=g" < filename.tmp > newfilename
Here's another approach

. /temp/table
for value in $(cut -f3 -d, file | sed s/\"//g)
  tab=$(eval echo \$table_$value)
  sed -i.bak "s/$value/$tab/" file

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bjeAuthor Commented:
The solution worked well.   My table has double quotes around the value, however they are not showing up in the file.

I tried, sed -i.bak "s/$value/\"/$tab\"\/"  -  not working.   Will you let me know how to do this.

 sed -i.bak "s/$value/\"$tab\"/" 

Open in new window

bjeAuthor Commented:
Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.