3

我需要每天拆分包含 50K+ 列的巨大 (>1 Gb) CSV 文件。

我发现Miller是完成此类任务的有趣且高效的工具。

但我坚持米勒的文档。

如何将一个 CSV 拆分为N较小的 CSV 文件,其中N我的源文件中有许多行?

4

2 回答 2

6

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.

于 2019-04-15T10:24:22.973 回答
3

aborruso 的答案确实rule为输出的 csv 文件添加了一个新列。如果您想避免这种情况,请在最后一步中使用emitwithmapexcept而不是,如下所示: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
于 2021-06-09T14:51:19.937 回答