int mincol = Integer.MAX_VALUE
int maxcol = Integer.MIN_VALUE
values = [:]
new File("testfile.csv").eachLine {
cols = it.count(",") + 1
maxcol = maxcol<cols?cols:maxcol
mincol = mincol>cols?cols:mincol
if( values[cols] == null ){
values.put(cols, 1)
} else {
values.put(cols, ++values[cols])
}
}
println "max number of columns:${maxcol}"
println "min number of columns:${mincol}"
values.sort().each {
println "${it.key} columns -> ${it.value} lines."
}
動作環境
groovy 1.7.5, JDK6 Update22
0 件のコメント:
コメントを投稿