Hi,
I'm a first timer with Unix so pardon my ignorance.
I'm trying to read a comma separated file from the same folder where the script is and insert the value in a DB2 table.
I'm using AWK for the same. I'm getting `)' not expected error.
I'm not sure but for me it doesn't look like detailed error message. :wall:
The input file looks like this:
value1,value2,value3
The script is like this
awk '{
nbr=split($2,arr,",");
for(ix=1;ix<=nbr;ix++)
product_code=`echo 'print arr[ix]'`
db2 "INSERT INTO TABLE_NAME (PRODUCT_CODE) values (\'${product_code}\')
where NOT EXISTS
(select * from PRICING_PRODUCT_CODES where PRODUCT_CODE = \'${product_code}\');"
}' CODES.txt
awk '{print "db2 \"INSERT INTO TABLE_NAME (PRODUCT_CODE) values ("$1",) where NOT EXISTS (select * from TABLE_NAME where PRODUCT_CODE=("$1")\""}' RS=',' PRICING_PRODUCT_CODES.txt
And got the below error
The error context is
{print "db2 \"INSERT INTO PRICING_PRODUCT_CODES (PRODUCT_CODE, NETWORK_NAME, ACTIVE) values >>> ("$1",some <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-512 The string ,somevalue cannot contain a newline character. The source line is 1.
awk: 0602-540 There is a missing ) character.
awk '{
nbr=split($0,arr,",")
for(ix=1;ix<=nbr;ix++){
print "db2 \"INSERT INTO PRICING_PRODUCT_CODES (PRODUCT_CODE, NETWORK_NAME, ACTIVE) values (\'"arr[ix]"\',\'some value\',1) "
print "where NOT EXISTS (select * from TABLE_NAME where PRODUCT_CODE = \'"arr[ix]"\');\""
}' PRICING_PRODUCT_CODES.txt
And I got this error
0403-057 Syntax error at line 33 : `)' is not expected.
Basically, I want insert queries like this
Insert into table(col1,col2) values('valuefromfile1','staticvalue1') where ....;
Insert into table(col1,col2) values('valuefromfile2','staticvalue2') where ....;