title: Groovy csv parser and export to database
body: <p>How can I parse my CSV file without parsing first line ?</p>
  
  <p>This class work but I don't want to parse the header of my CSV.</p>
  
  <pre><code>import groovy.sql.Sql
  
  class CSVParserService {
  
      boolean transactional = false
  
      def sql = Sql.newInstance("jdbc:mysql://localhost/RProject", "xxx", "xxx", "com.mysql.jdbc.Driver")
  
      def CSVList = sql.dataSet("ModuleSet")
  
      def CSVParser(String filepath, boolean header) {
  
        def parse = new File(filepath)
  
        // split and populate GeneInfo
        parse.splitEachLine(',') {fields -&gt;
  
          CSVList.add(
                  Module : fields[0],
                  Function : fields[1],
                  Systematic_Name : fields[2],
                  Common_Name : fields[3],
                )
  
           return CSVList
        }
  
      }
  }
  </code></pre>
  
  <hr>
  
  <p>I change my Class, so now I have :</p>
  
  <pre><code>import groovy.sql.Sql
  
  class CSVParserService {
  
      boolean transactional = false
  
      def sql = Sql.newInstance("jdbc:mysql://localhost/RProject", "xxx", "xxx", "com.mysql.jdbc.Driver")
  
      def CSVList = sql.dataSet("ModuleSet")
  
      def CSVParser(String filepath, boolean header) {
  
      def parse = new File(filepath).readLines()[1..-1]
  
      parse.each {line -&gt;
  
        // split and populate GeneInfo
        line.splitEachLine(',') {fields -&gt;
  
          CSVList.add(
                  Module : fields[0],
                  Function : fields[1],
                  Systematic_Name : fields[2],
                  Common_Name : fields[3],
                )
  
           return CSVList
        }
       }
      }
  }
  </code></pre>
  
  <p>Works fine, until this part in my CSV :<br>
  "Homo sapiens interleukin 4 receptor (IL4R), transcript variant 1, mRNA."</p>
  
  <p>When my parser get this part, he cut in 3 (should be in 1) :<br>
  - Homo sapiens interleukin 4 receptor (IL4R)<br>
  - transcript variant 1<br>
  - mRNA.     </p>
  
  <p>How can I fix that ?
  Thank you for your help.</p>
  
  <p>-- New comment --
  Here is a copy (2nd line) of my CSV line :<br>
  "M6.6",NA,"ILMN_1652185",NA,NA,"IL4RA; CD124",NA,"NM_000418.2","16","16p12.1a","Homo sapiens interleukin 4 receptor (IL4R), transcript variant 1, mRNA.",3566,...</p>
  
  <p>As you can see my problem is in line "Homo sapiens interleukin 4 receptor (IL4R), transcript variant 1, mRNA." ; I don't want to cut text between " and ". My parser should only split ',' out of quotes (but not commas between quotes).
  For example I have : "part1","part2","part3", I just want cut part1, part2, part3, and if there are commas in my part2, I don't want to cut these commas.</p>
  
  <p>To sum up, I just want Ignoring commas in quoted elements.</p>