I am trying to compare these two YAML
files and trying to extract the key-value pair from the first file if key matches between these two files. Look at the expected output for more clarity.
YAML File 1:
COMMON-VAR: "[\n { \"DESC\": \"A\", \"O\": \"h\", \"confidence\":0.8 },\n { \"DESC\": \"B\", \"O\": \"u\", \"C\":0.8 }\n { \"DESC\": \"A\", \"O\": \"h\", \"confidence\":0.8 },\n "
LASTNAME: "D"
FIRSTNAME: "JOHN"
UNKNOWN: "!!"
YAML File 2:
COMMON-VAR: "[\n { \"DESC\": \"A\", \"O\": \"h\", \"confidence\":0.8 },\n { \"DESC\": \"B\", \"O\": \"u\", \"C\":0.8 }\n"
LASTNAME: "E"
FIRSTNAME: "JOHN"
ADDRESS: "SanJose, CA"
ZIP: "09817"
Expected output:
COMMON-VAR: "[\n { \"DESC\": \"A\", \"O\": \"h\", \"confidence\":0.8 },\n { \"DESC\": \"B\", \"O\": \"u\", \"C\":0.8 }\n { \"DESC\": \"A\", \"O\": \"h\", \"confidence\":0.8 },\n "
LASTNAME: "D"
My Attempt:
join <(sort file1.yaml) <(sort file2.yaml) | awk '$2!=$3{print $1,$3}' | yq e -I4
It works when I don't have curly braces in my values, but awk
fails when I have {}
in my value in yaml
file.