I\'m using groovy to concatenate two fields in CSV It\'s working ok except that the concatenated field is appearing with quotes.
Is there any way to resolve this?
<
CSV is a more complicated file format than it would first appear. Fields can be optionally quoted which is what appears to be your problem.
Most programming languages have a library that will parse CSV. In the case of groovy I'd recommend opencsv
http://opencsv.sourceforge.net/
The following example extends the example I created for your previous question.
├── build.xml
├── src
│ └── file1.csv
└── target
└── file1.csv
"customer",deal
"200000042",23
"200000042",34
"200000042",35
"200000042",65
customer,deal,customer-deal
200000042,23,200000042-23
200000042,34,200000042-34
200000042,35,200000042-35
200000042,65,200000042-65
import com.opencsv.CSVReader
ant.mkdir(dir:"target")
new File("target/file1.csv").withWriter { writer ->
new File("src/file1.csv").withReader { reader ->
CSVReader csv = new CSVReader(reader);
csv.iterator().each { row ->
if (row.size() == 2) {
writer.println "${row[0]},${row[1]},${row[0]}-${row[1]}"
}
}
}
}
Notes: