The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 01-07-2009
inquisitive101 inquisitive101 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 5
Ok now how about if I have a new scenario where my .csv file looks like this :

a, b ,c ,d
a ,b, c, d
a, b, c, d
e, b, c ,d
e ,b, c ,d
e ,b ,c, d


My output should b 3 insert queries,that are only slightly different. i.e :

insert into table_xyz values(123, $a, 'abcd4', 601, $b, $c, $d ,32425)
insert into table_xyz values(124, $a, 'abcd4', 602, $b, $c, $d ,32425)
insert into table_xyz values(125, $a, 'abcd4', 603, $b, $c, $d ,32425)
insert into table_xyz values(126, $e, 'abcd4', 601, $b, $c, $d ,32425)
insert into table_xyz values(127, $e, 'abcd4', 602, $b, $c, $d ,32425)
insert into table_xyz values(128, $e, 'abcd4', 603, $b, $c, $d ,32425)

the problem is the way the 2nd and 4th fields in the query should b printed. while the 2nd field should b repeated 3 times(as in read each line of the data file), the 4th field increments to 3 and goes back after every 3rd line of the file...

any suggestions...? need a shell script ...

i tried modifying shell script given by Christoph but the output is such that the same 3 queries are repeated as many times as there lines in my data file before moving on...