The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
parsing a string in a shell script asutoshch Shell Programming and Scripting 19 05-26-2008 10:18 PM
question to build a shell script vishalpatel03 Shell Programming and Scripting 5 12-12-2007 12:45 PM
shell script string extension vbm Shell Programming and Scripting 4 11-10-2006 01:58 AM
Reversing and trim a String through SHELL script DeepakXavier Shell Programming and Scripting 5 09-28-2005 10:25 AM
Shell script: Cut / (slash) character in string ThuongTranVN UNIX for Dummies Questions & Answers 4 01-30-2001 12:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-16-2008
nkosaraju nkosaraju is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 7
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
  #2 (permalink)  
Old 07-16-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,345
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
  #3 (permalink)  
Old 07-16-2008
nkosaraju nkosaraju is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 7
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 (permalink)  
Old 07-16-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,345
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
  #5 (permalink)  
Old 07-16-2008
nkosaraju nkosaraju is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 7
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
  #6 (permalink)  
Old 07-16-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,345

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
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0