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

  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 Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 07-16-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 17 December 2014, 7:05 AM EST
Location: The Netherlands
Posts: 7,720
Thanks: 126
Thanked 538 Times in 508 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 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 07-16-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 17 December 2014, 7:05 AM EST
Location: The Netherlands
Posts: 7,720
Thanks: 126
Thanked 538 Times in 508 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 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 07-16-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 17 December 2014, 7:05 AM EST
Location: The Netherlands
Posts: 7,720
Thanks: 126
Thanked 538 Times in 508 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 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12:36 AM.