Created
December 4, 2011 18:35
-
-
Save kellyrob99/1430935 to your computer and use it in GitHub Desktop.
OpenCSV in a groovy script to read in a file, filter the content and write out the result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group = 'net.sf.opencsv', module = 'opencsv', version = '2.3') | |
import au.com.bytecode.opencsv.CSVReader | |
import au.com.bytecode.opencsv.CSVParser | |
import au.com.bytecode.opencsv.CSVWriter | |
def TEST_FILE_NAME = 'test.csv' | |
def TEST_OUTPUT_FILE_NAME = 'testOut.csv' | |
List<String[]> rows = new CSVReader(new FileReader(new File(TEST_FILE_NAME)), CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_ESCAPE_CHARACTER, CSVParser.DEFAULT_QUOTE_CHARACTER, 1).readAll() | |
def rowsOver100 = rows.findAll {it[1].toInteger() > 100} | |
File output = new File(TEST_OUTPUT_FILE_NAME) | |
if (output.exists()) | |
{ | |
output.delete() | |
} | |
output.createNewFile() | |
output.withWriter { writer -> | |
new CSVWriter(writer).writeAll(rowsOver100) | |
} | |
//println rows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment