Iokanaan Iokan
Iokanaan Iokan

Reputation: 775

extracting multiple strings from a line

I have the following json (only a longer version with hundreds of ids) and it is a one line document:

{"jsonrpc":"2.0","result":[{"templateid":"10001"},{"templateid":"10047"},{"templateid":"10050"}],"id":2}

I want to extract the ids and write them into a file so that it would look like this:

10001
10047
10050

Couldn't figure this out myself. Appreciate any help. This is CentOS by the way.

Upvotes: 2

Views: 61

Answers (1)

kev
kev

Reputation: 161674

You can use jq:

jq -r '.result[].templateid' input.json

It's a very good tool. Please download the binary, chmod +x jq, read the manual.

Upvotes: 7

Related Questions