将项目符号编号列表解析为UNIX中面向模式的csv?

时间:2019-03-11 15:33:49

标签: regex bash parsing unix

我能够将传入的多级合并Yaml解析为项目符号数据文件。感谢How can I parse a YAML file from a Linux shell script?。 现在正在寻找分析项目符号编号的数据文件以提取配置单元。但是数据必须是示意图,嵌套对象会保留到底部。我无法在框中安装任何新的json / yaml解析器,因此必须使用awk / sed / regex常用方法来生成它。任何帮助都很好

例如输入文件:

1="name: exports"
1_1="name: Wolverine"
1_1_description="BLA BLA"
1_1_active_date="2019-01-07 00:00:00"
1_1_1="name: strength"
1_1_1_type="superhuman"
1_1_2="name: power"
1_1_2_type="plasma"
1_1_2_description="XYZ"
1_1_2_example="21352352"
1_2="name: Cyclops"
1_2_description="BLA BLA"
1_2_active_date="2018-12-18 00:00:00"
1_2_1="name: speed"
1_2_1_type="datetime"
1_2_1_description="|-"
1_2_1_example="xyz"
1_2_2="name: agility"
1_2_2_type="bigint"
1_2_2_description="something"
1_2_2_example="21352352"

csv中的预期输出:

Wolverine,strength,superhuman,,
Wolverine,power,plasma,XYZ,21352352
Cyclops,speed,datetime,|-,xyz
Cyclops,agility,bigint,something,21352352

想法是将其解析为以下表格中的蜂巢:

<table class="tableizer-table">
<thead><tr class="tableizer-firstrow"><th>Level 1(name)</th><th>Level 2(name)</th><th>Level 2 (type)</th><th>Level 2 (description)</th><th>Level 2 (example)</th></tr></thead><tbody>
 <tr><td>Wolverine</td><td>strength</td><td>superhuman</td><td>&nbsp;</td><td>&nbsp;</td></tr>
 <tr><td>Wolverine</td><td>power</td><td>plasma</td><td>XYZ</td><td>21352352</td></tr>
 <tr><td>Cyclops</td><td>speed</td><td>datetime</td><td>|-</td><td>xyz</td></tr>
 <tr><td>Cyclops</td><td>agility</td><td>bigint</td><td>something</td><td>21352352</td></tr>
</tbody></table>

0 个答案:

没有答案