我如何解析Linux shell脚本中的yaml文件

时间:2016-07-06 07:37:16

标签: linux shell yaml

我的YAML文件如下:

report_id: demographics
columns:
- date
- channel_id
- video_id
- claimed_status
- uploader_type
- live_or_on_demand
report_id: device_os
columns:
- date
- channel_id
- video_id
- asset_id
- claimed_status
- uploader_type
- live_or_on_demand
- subscribed_status
- country_code
- device_type
- operating_system

我想使用shell脚本解析我的YAML文件,并希望答案为:

report_id: demographics
date
channel_id
video_id
claimed_status
uploader_type
live_or_on_demand
report_id: device_os
date
channel_id
video_id
asset_id
claimed_status
uploader_type
live_or_on_demand
subscribed_status
country_code
device_type
operating_system

1 个答案:

答案 0 :(得分:1)

sed '/columns:/d;s/^\s*-\s*//g' file.yml