简体   繁体   中英

Recursive cat all the files into single file

I have bunch of files sitting in folders like

data\A\A\A\json1.json
data\A\A\A\json2.json
data\A\A\B\json1.json
...
data\Z\Z\Z\json_x.json

I want to cat all the jsons into one single file?

find data/ -name '*.json' -exec cat {} \; > uber.json

a short explanation:

find <where> \
  -name <file_name_pattern> \
  -exec <run_cmd_on_every_hit> {} \; \
    > <where_to_store>

Use find to get all the JSON files and concatenate them.

find data -name '*.json' -exec cat {} + > all.json

Note that this will not be valid JSON. If you want a JSON file to contain multiple objects, they need to be in a containing array or object, so you'd need to add [ ] around them and put , between each one.

或者 - 如果您有一个文件列表 - 您可以将其传递给xargs

<path to your files> | xargs cat > all.json
find ./ -type f | xargs cat > ../singlefilename

I would like this ,easy and simple.

../ avoid the error input file is output file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM