I have a text file with several blocks with several lines that may look like this:
{ key1: value, key2: value,
key3: value,
key4: value, key5: value }
{ key1: value, key2: value, key3: value,
key4: value, key5: value }
Given a key
, how can I get all the corresponding values?
Note that neither the key names nor the values have a fixed length, blocks start and finish with braces and pairs are separated by commas.
My first try was with grep
and cut
, but I couldn't get all the keys. I guess that this should be easy with sed
or awk
, but their syntax confuses me a lot.