How to build a string in shell script | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to build a string in shell script

Shell Programming and Scripting


Tags
solaris

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-16-2008
nkosaraju nkosaraju is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 6 August 2008, 9:26 PM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 07-16-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 6 March 2015, 3:59 AM EST
Location: The Netherlands
Posts: 7,727
Thanks: 128
Thanked 543 Times in 511 Posts
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
Sponsored Links
    #3  
Old Unix and Linux 07-16-2008
nkosaraju nkosaraju is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 6 August 2008, 9:26 PM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
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
    #4  
Old Unix and Linux 07-16-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 6 March 2015, 3:59 AM EST
Location: The Netherlands
Posts: 7,727
Thanks: 128
Thanked 543 Times in 511 Posts
One way:


Code:
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
Sponsored Links
    #5  
Old Unix and Linux 07-16-2008
nkosaraju nkosaraju is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 6 August 2008, 9:26 PM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #6  
Old Unix and Linux 07-16-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 6 March 2015, 3:59 AM EST
Location: The Netherlands
Posts: 7,727
Thanks: 128
Thanked 543 Times in 511 Posts

Code:
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:
Code:
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
Sponsored Links
    #7  
Old Unix and Linux 07-16-2008
nkosaraju nkosaraju is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 6 August 2008, 9:26 PM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a lot.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comparing a String variable with a string literal in a Debian shell script daveu7 UNIX for Dummies Questions & Answers 1 03-14-2012 09:37 AM
build a string of asterisks elegantly lazybaer Shell Programming and Scripting 18 02-18-2012 03:38 PM
Need to build Shell Script to search content of a text file into a folder consist several files mukesh.baranwal Shell Programming and Scripting 3 09-16-2011 08:10 AM
how to build a pipe delimited string jdsignature88 Shell Programming and Scripting 1 07-07-2010 08:25 PM
question to build a shell script vishalpatel03 Shell Programming and Scripting 5 12-12-2007 12:45 PM



All times are GMT -4. The time now is 08:34 AM.