我需要每天拆分包含 50K+ 列的巨大 (>1 Gb) CSV 文件。
我发现Miller是完成此类任务的有趣且高效的工具。
但我坚持米勒的文档。
如何将一个 CSV 拆分为N
较小的 CSV 文件,其中N
我的源文件中有许多行?
try with this script
mlr --csv put -S 'if (NR % 10000 == 0) {$rule=NR} else {$rule = ""}' \
then fill-down -f rule \
then put -S 'if ($rule=="") {$rule="0"}' \
then put -q 'tee > $rule.".csv", $*' input.csv
Make a copy of your CSV in a new folder, and then run this script on it. It will produce a csv file for every 10000 rows.
aborruso 的答案确实rule
为输出的 csv 文件添加了一个新列。如果您想避免这种情况,请在最后一步中使用emit
withmapexcept
而不是,如下所示:tee
mlr --csv put -S 'if (NR % 10000 == 0) {$rule=NR} else {$rule = ""}' \
then fill-down -f rule \
then put -S 'if ($rule=="") {$rule="0"}' \
then put -q 'emit > $rule.".csv", mapexcept($*, "rule")' input.csv