Moh*_*hit 47 unix linux bash grep cat
我有一堆文件坐在文件夹中
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
Run Code Online (Sandbox Code Playgroud)
我想把所有的jsons都塞进一个文件中?
Pav*_*vel 86
find data/ -name '*.json' -exec cat {} \; > uber.json
Run Code Online (Sandbox Code Playgroud)
一个简短的解释:
find <where> \
-name <file_name_pattern> \
-exec <run_cmd_on_every_hit> {} \; \
> <where_to_store>
Run Code Online (Sandbox Code Playgroud)
Bar*_*mar 13
使用find
让所有的JSON文件,将它们连接起来.
find data -name '*.json' -exec cat {} + > all.json
Run Code Online (Sandbox Code Playgroud)
请注意,这不是有效的JSON.如果您希望JSON文件包含多个对象,则它们需要位于包含数组或对象中,因此您需要[ ]
在它们周围添加并放在,
每个对象之间.
csi*_*siu 10
或者 - 如果你有一个文件列表 - 你可以管道 xargs
<path to your files> | xargs cat > all.json
Run Code Online (Sandbox Code Playgroud)
find ./ -type f | xargs cat > ../singlefilename
Run Code Online (Sandbox Code Playgroud)
我想要这个,简单易行。
../
避免错误input file is output file
。
归档时间: |
|
查看次数: |
63102 次 |
最近记录: |