GroovyCSV is a library to make csv processing just a little bit Groovier. The library uses opencsv behind the scenes and merely tries to add a thin layer of “Groovy-ness” to the mix.
findAll, collect and so on)@Grab('com.xlson.groovycsv:groovycsv:1.0')
import com.xlson.groovycsv.CsvParser
def csv = '''Name-Lastname
Mark-'Anderson-Nielsen'
Pete-Hansen'''
def data = new CsvParser().parse(csv, separator: '-', quoteChar: "'")
for(line in data) {
println "$line.Name $line.Lastname"
}
Output:
Mark Andersson
Pete Hansen
@Grab('com.xlson.groovycsv:groovycsv:1.0')
import com.xlson.groovycsv.CsvParser
def csv = '''Apple,2
Pear,5'''
def data = new CsvParser().parse(csv, readFirstLine:true,
columnNames:['fruit', 'qty'])
for(line in data) {
println "$line.fruit ${line[1]}"
}
Output:
Apple 2
Pear 5
Apache V2
Leonard Axelsson (leo@xlson.com)
GroovyCSV 1.0
GroovyCSV 0.2
You can also clone the project with Git by running: $ git clone git://github.com/xlson/groovycsv