Max Korn
Max Korn

Reputation: 275

Which Unix command to get a number from inside this string?


I'd like to hear your suggestions about collecting from this string (which returned by a command) the value which is next to result (In this case 15) :

{
    "outcome" => "success",
    "result" => 15
}

Which utility/command to do suggest me ? Thanks Max

Upvotes: 2

Views: 98

Answers (3)

Dan Moulding
Dan Moulding

Reputation: 220463

$ awk '$1 == "\"result\"" { print $3 }' <<< "$STRING"

Upvotes: 2

Lev Levitsky
Lev Levitsky

Reputation: 65781

GNU grep:

command | grep -oP '(?<="result" => )\d+'

Upvotes: 4

John Kugelman
John Kugelman

Reputation: 361555

command | awk '$1=="\"result\"" {print $3}'

Upvotes: 4

Related Questions