如何将yaml文件拆分为多个文件? [英] How to split yaml file into several files?
问题描述
我有一个大(〜2Gb)yaml
文件.我使用yaml-cpp
库和YAML::Loadfile
函数.但是我有一个内存不足的问题.
I have a big (~2Gb) yaml
file. I use yaml-cpp
library and YAML::Loadfile
function. But I have an issue of RAM shortage.
将这个文件分成几个小文件的最简单方法是什么,即每个小文件都是一个有效的yaml
文件(可能是Linux的功能)?
What is the easiest way to split this file into several small ones in a way that each small file would be a valid yaml
file (maybe by capabilities of linux)?
推荐答案
如果文件中有多个文档,则可以在该行的开头拆分---
.
If you have multiple documents in your file and then you could split upon ---
at the beginning of the line.
如果您没有多个文档(或者,如果您有多个文档,但它们仍然太大),则您的文档要么在顶层具有映射关系,要么在序列上具有映射关系(理论上您也可以有多行)标量,但这不太可能).
If you don't have multiple documents (or if you have multiple ones, but they are still too big), your document either has mapping at the top level or a sequence (in theory you can also have a multi-line scalar, but that is unlikely).
如果文档的顶层具有流样式(使用{ }
进行映射,使用[ ]
进行序列化),那么事情就很大程度上取决于布局的方式.但是,如果它具有块样式,则可以轻松找到顶级映射的各个键或序列的元素.它们都具有与第一个元素相同的缩进(最有可能是零缩进).
If the toplevel of your document has flow style (mapping with { }
, sequence with [ ]
) then things are very dependent on how the layout is. But if it has block style then you can easily find the individual keys of the top-level map, or the elements of the sequence. They all have the same indentation as the first element (most likely zero indent).
根据上述信息拆分您的YAML文档,并自行处理每个元素.
Split your YAML document based on the above information and process each element on its own.
这篇关于如何将yaml文件拆分为多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!