Assuming your input file contains more than 1 name-value pair, consider this:
$ awk -F'":"' '{gsub(/^[[:space:]]*"|"[[:space:]]*$/,""); f[$1]=$2} END{print f["key"]}' file
JIRA-90
That approach lets you populate an array (f[]
above) with the name to value mappings and then you can just print the values by their names whenever you like.
$ cat file
"foo":"127"
"key":"JIRA-90"
"bar":"hello world"
$ awk -F'":"' '{gsub(/^[[:space:]]*"|"[[:space:]]*$/,""); f[$1]=$2} END{print f["bar"], f["key"]}' file
hello world JIRA-90
$ awk -F'":"' '{gsub(/^[[:space:]]*"|"[[:space:]]*$/,""); f[$1]=$2} END{print f["foo"] * 3}' file
381
$ awk -F'":"' '{gsub(/^[[:space:]]*"|"[[:space:]]*$/,""); f[$1]=$2} END{for (i in f) print i "=" f[i]}' file
key=JIRA-90
foo=127
bar=hello world
jq
, which is designed to parse JSON (which, being an irregular language, is something thatsed
is not). – DopeGhoti Feb 07 '20 at 20:00