How to build a string in shell script

Hi all,

I had a typical problem.

I am using a parameter
PK="PK1 PK2 PK3"

i need to build the string

a.PK1=b.PK1 and a.PK2=b.PK2 and a.PK3=b.PK3

Please help

Can you explain what parameter it is, which programming/scripting language/shell and what you're trying to achieve?
Show a snippet of your code.

Regards

It is a parameter from param file or config file u can say.
I want to use that parameter in a shell script and build the above string so that i can use it in where clause of my query.
Thanks

One way:

echo 'PK="PK1 PK2 PK3"' |
awk -F"\"" '{split($2,s," ")
print "a."s[1]"=b."s[1]" and a."s[2] "=b."s[2] " and a."s[3] "=b."s[3]}'

Regards

Hi Thank you.

It was printing the required result.

Can you help me in assigning it to a variable.

i tried
PK_STR= echo 'PK="PK1 PK2 PK3"' |
awk -F"\"" '{split($2,s," ")
print "a."s[1]"=b."s[1]" and a."s[2] "=b."s[2] " and a."s[3] "=b."s[3]}'
it is not working
Thanks

PK_STR=`echo 'PK="PK1 PK2 PK3"' |
awk -F"\"" '{split($2,s," ")
print "a."s[1]"=b."s[1]" and a."s[2] "=b."s[2] " and a."s[3] "=b."s[3]}'`

or:

PK_STR=$(echo 'PK="PK1 PK2 PK3"' |
 awk -F"\"" '{split($2,s," ")
 print "a."s[1]"=b."s[1]" and a."s[2] "=b."s[2] " and a."s[3] "=b."s[3]}')

Regards

Thanks a lot.

Hi

I am getting the following error when assiging it to PK_STR

a.PK1=b.PK1: not found

please help

Thanks

Hard to see where it goes wrong, try nawk, gawk or /usr/xpg4/bin/awk on Solaris. Post a snippet of your script if that isn't the problem.

Regards