Using PCRE-enabled pgrepgrep implementations:
grep -Po '(^|[ ,])KEY1:\K[^,]*' or egrep and cut:
grep -Eo '(^|[ ,])KEY2:[^,]*' | cut -d: -f2- For both methods, the Value is not allowed to contain comma.
If you had proper json, e.g.
{ "KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3" } you could use jq:
$ jq .KEY2 "VALUE2" $ jq -r .KEY2 VALUE2