![]() |
|
|
|||||||
| 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 |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|
|||
|
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 |