Issue
Input file
- name: APPENV
value: STAGING
- name: ELASTICSEARCH_USER
value: elastic
- name: WRITE_LOGS_TO_ELASTICSEARCH
value: "true"
- name: version
value: "5"
Expected output:
APPENV: STAGING
ELASTICSEARCH_USER: elastic
WRITE_LOGS_TO_ELASTICSEARCH: "true"
version: "5"
tried awk -F "e:" '{print $2}' filename
to abstract only key and value, but need to align this as above output. Any help would be appreciated
Solution
This works:
awk '
sub(/^[[:space:]]+- name: /, ""){n=$0}
sub(/^[[:space:]]+value: /, ""){print n": "$0}'
Match and remove the name:
/value:
labels, and print the remainder of both lines on a single line.
Answered By - dan Answer Checked By - Dawn Plyler (WPSolving Volunteer)