The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


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


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help concatenation string and variable drain Shell Programming and Scripting 5 02-18-2008 06:21 AM
cannot get logic for concatenation awk user_prady Shell Programming and Scripting 7 12-09-2007 11:09 PM
Concatenation Asteroid Shell Programming and Scripting 11 04-04-2007 03:15 AM
string concatenation systemsb UNIX for Dummies Questions & Answers 7 04-04-2006 09:03 AM
Concatenation videsh77 Shell Programming and Scripting 2 12-14-2004 02:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-16-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
String concatenation issue in ksh

Hello All,

I'm tryying to concatenate string and variables value in ksh, but i'm unable to do it, can someone please help in rectifying my error,

here is the code i have written,

#!/usr/bin/ksh -x
cat $1 | while read fileline
do
val1= echo $fileline | awk -F, '{print $1}'
val2= echo $fileline | awk -F, '{print $2}'
set sqlstmt = "update Tablename set Varnum1 = $val2 where Date = '$val1' and UId = 1"
#echo $fileline
echo $sqlstmt
#echo $val1
#echo $val2
done


Data there in input file is something like ,

20080401,16540448,52267816,2559665,8088541
20080402,16599900,52455684,2741819,8664148


Any help will be much appriciated, as i have been trying various combination from last few hours like putting the variable name in {} , i.e ${val2}, etc

Thanks,
Arvind.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-16-2008
Registered User
 

Join Date: Apr 2008
Location: Bangalore
Posts: 120
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Hi,,
Try this

#!/usr/bin/ksh -x
cat $1 | while read fileline
do
val1=`echo $fileline | awk -F, '{print $1}'`
val2=`echo $fileline | awk -F, '{print $2}'`
sqlstmt="update Tablename set Varnum1 = $val2 where Date = '$val1' and UId = 1"
#echo $fileline
echo $sqlstmt
#echo $val1
#echo $val2
done


Just added back quotes while fetching val and val2 values .
and removed set.

Thanks
Penchal
Reply With Quote
  #3 (permalink)  
Old 05-16-2008
Moderator
 

Join Date: Dec 2003
Location: /ksh93
Posts: 715
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
No need to use set, awk or cat. Simply set IFS to the delimiter to split the line.
Code:
#!/usr/bin/ksh

IFS=','
while read val1 val2 rest
do
   sqlstmt="update Tablename set Varnum1 = $val2 where Date = '$val1' and UId = 1"
   print $sqlstmt
done < $1
Reply With Quote
  #4 (permalink)  
Old 05-16-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Thats wonderfull idea, thanks all for the help, i have been able to do it both ways
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB 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 -7. The time now is 03:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102