Skip to content

Instantly share code, notes, and snippets.

@marcgeld
Last active September 15, 2016 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcgeld/3ed8d11751c63dd9f56ba57fff4b82fc to your computer and use it in GitHub Desktop.
Save marcgeld/3ed8d11751c63dd9f56ba57fff4b82fc to your computer and use it in GitHub Desktop.
Makes a large csv file
#!/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)"
@marcgeld
Copy link
Author

Changed typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment