Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

split files to key value pair

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading