String concatenation issue in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String concatenation issue in ksh
# 1  
Old 05-16-2008
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.
# 2  
Old 05-16-2008
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
# 3  
Old 05-16-2008
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

# 4  
Old 05-16-2008
Thats wonderfull idea, thanks all for the help, i have been able to do it both ways Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk concatenation issue - SQL generation

Greetings Experts, I have an excel file and I am unable to read it directly into awk (contains , " etc); So, I cleansed and copied the data into notepad. I need to generate a script that generates the SQL. Requirement: 1. Filter and select only the data that has the "mapping" as "direct"... (4 Replies)
Discussion started by: chill3chee
4 Replies

2. Shell Programming and Scripting

Help with String concatenation

I have a script which is migrated from AIX to Linux & now while running it is no able to concatenate string values The string concatenation step under while loop is not displaying desired result Please find below the piece of code: while read EXT_FILE ; do EXT_FILE=$EXT_FILE.ext.sent echo... (7 Replies)
Discussion started by: PreetArul
7 Replies

3. Shell Programming and Scripting

Group by and string concatenation

Hi, I was trying to work on a file which had the following data format 1 hi 1 this 1 is 1 john 2 hello 3 test 3 case the expected output file is the below 1 hi, this, is, john 2 hello 3 test, case I tried using awk or while read, but I couldnt... (13 Replies)
Discussion started by: karthikbhuvana
13 Replies

4. Shell Programming and Scripting

String concatenation problem

Hi there, I'm writing a basic script where I want to make a string of 2 numeric fields from a file, which I have done, but the behavior is rather confusing. I have a file of random values such as: 1 2 3 4 5 6 7 8 9 10 and my awk code is: BEGIN { FS = " " } { str = str $1 $2 } END {... (7 Replies)
Discussion started by: HMChadwick
7 Replies

5. Shell Programming and Scripting

String concatenation

Hi, I have two files. cat file.txt a b c d cat file1.txt j k l m I need the output as a:j (12 Replies)
Discussion started by: nareshkumar522
12 Replies

6. Shell Programming and Scripting

reading value of concatenation with ksh

hello all, I am trying to read the value of a concatenation, the following code is displaying $word1 $word2 I want to display village home Thanks for (( i=1; i<=2; i++ )) do word1='village' word2='home' con="$"word"$i" echo $con done (5 Replies)
Discussion started by: wydadi
5 Replies

7. Shell Programming and Scripting

String concatenation problems

#! /bin/csh set tt=12345_UMR_BH452_3_2.txt set rr=`echo $tt | cut -d_ -f1` set rr1=welcome set ff=$rr $rr1 echo $ff why $ff returned only 12345 and not 12345welcome? thanks (2 Replies)
Discussion started by: jdsignature88
2 Replies

8. Shell Programming and Scripting

String/Variable Concatenation

Hello, Trying to concatenate the following using bourne shell: # !/bin/bash # this works in bash shell e.g. get the results I am expecting fnTmp=C$cindex.$station_0.$station_1.$station_3.$ts.tmp # # under !/bin/sh # the results are not the same Any assistance would be... (8 Replies)
Discussion started by: LAVco
8 Replies

9. Shell Programming and Scripting

String Concatenation

Hi All, I need to concatenate the values in the array into a variable. Currently the code is : for (( i=1 ; i <= $minCount ; i++ )) do var="${var}""${sample_file}" done The output is : /tmp/1/tmp/2/tmp/3/tmp/4/tmp/5/tmp/6/tmp/7/tmp/8/tmp/9/tmp/10 I need a space between... (1 Reply)
Discussion started by: sh_kk
1 Replies

10. UNIX for Dummies Questions & Answers

string concatenation

my input file contains thousands of lines like below 234A dept of education 9788 dept of commerce 8677 dept of engineering How do i add a delimeter ':' after FIRST 4 CHARACTERS in a line 234A:dept of education 9788:dept of commerce 8677:dept of engineering (7 Replies)
Discussion started by: systemsb
7 Replies
Login or Register to Ask a Question