Question: Creating a Bash Script File After you are satisfied with your hands-on log session in in Part 1 (previous question), create and execute a bash

Creating a Bash Script File

After you are satisfied with your hands-on log session in in Part 1 (previous question), create and execute a bash script using a text editor of your choice that does the following:

Scenario: Say that you have a .csv format file that you want to create INSERT statements to insert the data into a MySQL database.

For example, you want to write a script that reads the file students.csv and creates the file students.sql as shown below:

$ cat students.csv

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

$ cat students.sql

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');

Write a script, sqlinsert.sh, that will do this for you. In the sqlinsert.sh script, use a while loop that reads input data from the students.csv until the EOF.

Usage: ./sqlinsert.sh students.csv

Write a script called sqlinsert.sh that does the following:

Uses the while loop to read file input

Creates INSERT statements file students.sql

Be sure to upload both the script file sqlinsert.sh as well as the file students.sql as attachments to complete your lab Assignment 9.2 submission.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!