我有一个大约有500万条记录的CSV文件,我正尝试使用Json处理器jq将csv文件数据转换为json数组。但是,我需要将csv转换为每个具有10K记录的json数组(转换为单独的文件),而不是如以下示例中给出的具有500万个记录的单个json数组文件。
如何通过shell脚本实现此目标?或如何通过shellscipt将单个json数组转换为在json文件中具有10k记录的多个json数组?
输入csv文件:
identifier,type,locale
91617676848,msisdn,es_ES
91652560975,es_ES
91636563675,es_ES
csv到json的转换:
jq --slurp --raw-input --raw-output \
'split("\n") | .[1:] | map(split(",")) |
map({"identifier": .[0],"type": .[1],"locale": .[2]})' \
sample.csv > out_new.json
单个Json数组输出:
[
{
"identifier": "91617676848","type": "msisdn","locale": "es_ES"
},{
"identifier": "91652560975",{
"identifier": "91636563675","locale": "es_ES"
}
]
预期的Json输出。
1.json (having 10K json array records)
[
{
"identifier": "91617676848",.
.
.
.
{
"identifier": "91652560975","locale": "es_ES"
}
]
2.json (having 10K json array records)
[
{
"identifier": "91636563675",.
.
.
.
{
"identifier": "91636563999","locale": "es_ES"
}
]