I have below string, each line delimited by New Line as Input string
string="name: MAIN_ROLE
description: ROLE DESCRIPTION
readOnly:
roleReferences:
- roleTemplateAppId: app1
roleTemplateName: template2
name: Name1
- roleTemplateAppId: app2
roleTemplateName: template2
name: Name2
"
I like to print YAML string into comma delimited string as below result. Input string could have any number of component after "-" which makes new record but MAIN_ROLE value remain the same first column:
MAIN_ROLE,Name1,template1,app1
MAIN_ROLE,Name2,template2,app2
I tried below code to split the line with "- " but I am not getting correct result
echo "$a" | sed -n $'/^- $/,/^- $/p' <<< $string