Skip to content

Instantly share code, notes, and snippets.

@satyr
Forked from tyama/gist:18027
Created October 22, 2008 23:57
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 satyr/18865 to your computer and use it in GitHub Desktop.
Save satyr/18865 to your computer and use it in GitHub Desktop.
String fun(String fpath, List mods, Closure sorter){
def r = new File(fpath).text.trim().split(/\r?\n/)*.tokenize('\t')
mods.each{ r.(it.maximumNumberOfParameters==2?'eachWithIndex':'each') it }
[r.head(), *r.tail().sort(sorter)]*.join('\t').join('\n')
}
print fun('data.csv', [
{ it[0..3] = it[0, 2, 1, 3] },
{ a, i -> if(i){ [0, 3].each{ a[it] = a[it].toInteger() }; ++a[3] } },
]){ it[0] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment