title: Populate MySQL table using txt file and bash script
body: <p>I am trying to write a bash script that will take a text file and use its content to populate a MySQL table.</p>
  
  <p>The text file contains numerous entries that I will need to add to the table.</p>
  
  <p>Example of text file contents:</p>
  
  <pre><code>Firstname=bob
  Surname=ross
  Age=9
  Firstname=gary
  Surname=graeme
  Age=19
  Firstname=henry
  Surname=harry
  Age=23
  </code></pre>
  
  <p>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.</p>
  
  <p>I have used sed to remove all empty lines and lines beginning with "#" in the text file that I would not want to process. </p>
  
  <p>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.</p>
  
  <p>I know that I will need to have a new table entry every 3 lines.</p>
  
  <pre><code>echo "INSERT INTO $table (Firstname, Surname, Age) VALUES ('$Firstname', '$Surname', '$age');" | mysql $db
  </code></pre>
  
  <p>Thanks</p>