У меня огромный json-файл, ключи которого начинаются с "/".Я хотел создать несколько файлов JSON на основе имени ключа.
/upgrade-coordinator/api/v1/upgrade/eula/acceptance
/upgrade-coordinator/api/v1/upgrade/history
/upgrade-coordinator/api/v1/upgrade/nodes
/upgrade-coordinator/api/v1/upgrade/nodes-summary
/upgrade-coordinator/api/v1/upgrade/status-summary
/upgrade-coordinator/api/v1/upgrade/summary
/upgrade-coordinator/api/v1/upgrade/upgrade-unit-groups
/upgrade-coordinator/api/v1/upgrade/upgrade-unit-groups-status
После некоторых заметок на сайте я наткнулся на:
for f in `cat input.json | jq -r 'keys[]'` ; do
cat input.json | jq ".$f" > $f.json
done
or when you insist on more bashy syntax like some seem to prefer:
for f in $(jq -r 'keys[]') ; do
jq ".[\"$f\"]" < input.json > "$f.json"
done < input.json
Когда я попробовал описанное выше, я получаю ошибку:
-bash: -/nsxapi/api/v1/vpn/l2vpn/sessions/summary.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/eula/acceptance.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/history.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/nodes.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/nodes-summary.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/status-summary.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/summary.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/upgrade-unit-groups.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/upgrade-unit-groups-status.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/upgrade-unit-groups/aggregate-info.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/upgrade-units.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/upgrade-units-stats.json: No such file or directory
-bash: -/upgrade-coordinator/api/v1/upgrade/upgrade-units/aggregate-info.json: No such file or directory
Я думаю, что его, вероятно, bcos, он пытается создать aggregate-info.json в пути - / upgrade-координатор / api / v1 / upgrade / upgrade-units / - Если это правильно, как мне заменитьпервая строка "/" в каждом ключе к пробелу?Могу ли я получить помощь, пожалуйста?