Last active
September 15, 2016 09:40
-
-
Save marcgeld/3ed8d11751c63dd9f56ba57fff4b82fc to your computer and use it in GitHub Desktop.
Makes a large csv file
This file contains 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
#!/usr/bin/env groovy | |
// Run with: groovy MakeLargeCsvFile.groovy -r 12 --file a.csv | |
import groovy.text.SimpleTemplateEngine | |
def appName = this.getClass().getName() | |
def cli = new CliBuilder(usage:"${appName} --rows <row count> --file <path_to_file>") | |
cli.with { | |
r(longOpt: 'rows', 'expected row count', args: 1, required: true) | |
f(longOpt: 'file', 'File to Write', args: 1, required: true) | |
} | |
def templateIn = '${row};${valueEtt};${valueTva};${valueTree}\n' | |
def options = cli.parse(args) | |
if (!options) return | |
if (options.h) cli.usage() | |
int rowCnt = options.r.toInteger() | |
File outputFile = new File(options.f) | |
FileWriter writer = new FileWriter(outputFile) | |
def engine = new groovy.text.SimpleTemplateEngine() | |
(1..rowCnt).each{ idx -> | |
def binding = [row:idx, valueEtt:"value_ett_${idx}", valueTva:"value_tva_${idx}", valueTree:sprintf("%020d_%020d", idx, idx)] | |
def template = engine.createTemplate(templateIn).make(binding) | |
print "." | |
if ((idx % 100) == 0) { | |
print "(${idx})" | |
} | |
writer.write(template.toString()) | |
} | |
writer.flush() | |
writer.close() | |
println "Created File: '${outputFile.absolutePath}' with ${rowCnt} rows (${outputFile.length()} bytes)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changed typo