I want to write a script that reads the csv file and create the sql file? So I have several data in file.csv files like:
Ball,Jamin,1414 Willow Rd.,Cupertino,CA,94024
Church,Joe,2500 Main St.,Los Altos,CA,94023
Foothill,Ann,12345 El Monte Rd.,Los Altos,CA,94022
And I want to write a code in Linux to get the csv file like above and create the file.sql code so I can use that sql file for insert purpose. For example, I want the code will be like this in .sql file
INSERT INTO students (lname,fname,address,city,state,zip) VALUES
('Ball', 'Jamin', '1414 Willow Rd.', 'Cupertino', 'CA', '94024');
INSERT INTO students (lname,fname,address,city,state,zip) VALUES
('Church', 'Joe', '2500 Main St.', 'Los Altos', 'CA', '94023');
INSERT INTO students (lname,fname,address,city,state,zip) VALUES
('Foothill', 'Ann', '12345 El Monte Rd.', 'Los Altos', 'CA', '94022');
So for example, I say,
./generateSQL.sh file.csv
and it will generate and (create) and save the .sql file. Is it possible?
Here is what I have done so far:
awk -F',' '{ print "insert into " $1 " VALUES(" $2 ", " $3 ", " $4 ", " $5 ", " $6 ", " $7 ");" }' input.csv > output.log
My Code is only works for first line and I actually want this happen till all lines generated to SQL and I want this as a Generate.sh file that I can do below in my Linux. Not sure how:
./generateSQL.sh file.csv