Appending string, variable to file at the start and string at end
Hi ,
I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;"
It is not working . Can u please make this one work or new one .....
Code:
=============
V1S="INSERT INTO schema.table VALUES (" <-- mostly constant value string
V1E=") ; commit ;" <-- mostly constant value string
node=$1 <-- passing value and varies (lets say here it is 10)
awk '{print $V1S $node ","$2","$3","$4","$5","$6","$7","$8","$9","$10","$11","$12","$13 $V1E}' File1 > File2
Source_File:
-------------
0x0780000072F98E00 17 155 n/a 17 155 TAB1 SCH1 Perm 1 0 1 0
0x07800000747BF380 36 475 n/a 36 475 TAB1 SCH1 Perm 2 0 0 0
0x078000009A2A8600 36 476 n/a 36 476 TAB1 SCH1 Perm 11396 0 0 0
Expected Result in Target File:
-----------------------------
INSERT INTO schema.table VALUES (10,17,155,n/a,17,155,TAB1,SCH1,Perm,1,0,1,0); commit;
INSERT INTO schema.table VALUES (10,36,475,n/a,36,475,TAB2,SCH1,Perm,2,0,0,0); commit;
INSERT INTO schema.table VALUES (10,36,476,n/a,36,476,TAB2,SCH1,Perm,11396,0,0,0); commit;
Appreciate your help ...
Shyam
---------- Post updated at 11:24 AM ---------- Previous update was at 11:09 AM ----------
awk '{print "INSERT INTO scehma.table VALUES (" $2 "," $3 "," $4 "," $5 "," $6 "," $7 "," $8 "," $9 "," $10 "," $11 "," $12 "," $13 ") ; commit ;"}' File1 > File2
is working but how to get the "$node" varying variable value ???