Skip to content

Instantly share code, notes, and snippets.

@nobusue
Created April 4, 2011 09:21
Show Gist options
  • Save nobusue/901344 to your computer and use it in GitHub Desktop.
Save nobusue/901344 to your computer and use it in GitHub Desktop.
Simple CSV text merge script
def inputFiles = []
args.each{ fn ->
inputFiles << new File(fn)
}
new File('merged.csv').withWriter{ out ->
def outputLines = []
inputFiles.each{ file ->
def lineNo = 0
file.eachLine{ line ->
if(!outputLines[lineNo]) {
outputLines[lineNo] = [line]
} else {
outputLines[lineNo] << [line]
}
lineNo++
}
}
//outputLines.each{ println it.flatten().join(',') } //to Console
outputLines.each{ out << it.flatten().join(',') <<'\n' }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment