title: how to import text file into mysql table from bash using while loop
body: <p>I have a text file containing iana port listing. I want to import that file into mysql table from bash. but so far my columns gets mixed up. and mysql statement ends up inserting or reading data from the file and insert into wrong column in table. here's what the text file looks like. here's link to file I'm trying to import <a href="https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml" rel="nofollow noreferrer">https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml</a></p>
  
  <pre><code>mftp                349        tcp    mftp                         [Dave_Feinleib]                                       [Dave_Feinleib]
  mftp                349        udp    mftp                         [Dave_Feinleib]                                       [Dave_Feinleib]
  matip-type-a        350        tcp    MATIP Type A                 [Alain_Robert]                                        [Alain_Robert]                                                                      [RFC2351]
  matip-type-a        350        udp    MATIP Type A                 [Alain_Robert]                                        [Alain_Robert]                                                                      [RFC2351]
  matip-type-b        351        tcp    MATIP Type B                 [Alain_Robert]                                        [Alain_Robert]                                                                      [RFC2351]
  matip-type-b        351        udp    MATIP Type B                 [Alain_Robert]                                        [Alain_Robert]                                                                      [RFC2351]
  bhoetty             351        tcp    bhoetty                      [John_Kelly]                                          [John_Kelly]                                                                                                                                             This entry records an unassigned but widespread use (added
  </code></pre>
  
  <p>here's my script</p>
  
  <pre><code>cat service-names.txt | \
  while IFS=$'\t' read col1 col2 col3 col4 col5 col6; do 
  echo "INSERT INTO ports (id, service, number, proto, description, assign, notes) VALUES (DEFAULT, $col1, $col2, $col3, $col4, $col5, $col6);"
  done | sudo mysql -uroot -ppassword dbname
  </code></pre>
  
  <p>how to properly read the file... so I get a column per variable in my while loop... thanks</p>