Split JSON into multiple files

前端 未结 2 1752
误落风尘
误落风尘 2020-12-19 14:38

I have json file exported from mongodb which looks like:

{\"_id\":\"99919\",\"city\":\"THORNE BAY\"}
{\"_id\":\"99921\",\"city\":\"CRAIG\"}
{\"_id\":\"99922\         


        
相关标签:
2条回答
  • 2020-12-19 15:07

    Assuming you don't care about the exact filenames, if you want to split input into multiple files, just use split.

    jq -c . < cities.json | split -l 1 --additional-suffix=.json - .chunks/cities_
    
    0 讨论(0)
  • 2020-12-19 15:32

    In general to split any text file into separate files per-line using any awk on any UNIX system is simply:

    awk '{close(f); f=".chunks/cities_"NR".json"; print > f}' cities.json
    
    0 讨论(0)
提交回复
热议问题