[英]Split huge CSV by columns with Miller
I need to split huge (>1 Gb) CSV files containing 50K+ columns each on a daily basis.我需要每天拆分包含 50K+ 列的巨大 (>1 Gb) CSV 文件。
I've found Miller as an interesting and performant tool for such a task.我发现Miller是完成此类任务的有趣且高效的工具。
But I'm stuck on Miller's documentation.但我坚持使用 Miller 的文档。
How could I split one CSV to N
smaller CSV files where N
is a number of rows in my source file?我如何将一个 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.在新文件夹中复制您的 CSV,然后在其上运行此脚本。 It will produce a csv file for every 10000 rows.
它将为每 10000 行生成一个 csv 文件。
the answer from aborruso does add a new column rule
to the output csv files. aborruso 的回答确实向输出 csv 文件添加了一个新的列
rule
。 If you want to avoid this, use emit
with mapexcept
instead of tee
in the last step, like this:如果您想避免这种情况,请在最后一步中使用带有
mapexcept
的emit
而不是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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.