I am trying to write a bash script that will take a text file and use its content to populate a MySQL table.
The text file contains numerous entries that I will need to add to the table.
Example of text file contents:
Firstname=bob
Surname=ross
Age=9
Firstname=gary
Surname=graeme
Age=19
Firstname=henry
Surname=harry
Age=23
The text file is structured like the example above, the same 3 variables are constantly assigned new values for each unique entry that would go into the mysql table.
I have used sed to remove all empty lines and lines beginning with "#" in the text file that I would not want to process.
My question is how do I use bash to make an sql insert every three lines using the contents in textfile to generate the mysql query. I know I need to loop through the file 3 lines at a time until the end of the text file is reached and somehow parse each value after "=" and assign it to a variable in the loop iteration to insert the mysql data but I am not sure how to do this.
I know that I will need to have a new table entry every 3 lines.
echo "INSERT INTO $table (Firstname, Surname, Age) VALUES ('$Firstname', '$Surname', '$age');" | mysql $db
Thanks