1

I have a file called result which looks like this:

{"id":10722,"type":"BRANCH","value":"refs/heads/master","branch":{"id":"refs/heads/master","displayId":"master","latestChangeset":"d53ae5dbaa5e4b2f7b007e94ee91ae2de7e600b6","isDefault":true}}

Using bash, How can I put the substring after "id:" (in this example 10722) inside a parameter? (e.g param=10722)

I need to keep in mind that this file is changing all the time so counting characters is not something I would want to use.

Shahar Hamuzim Rajuan
  • 5,610
  • 9
  • 53
  • 91

1 Answers1

1

This looks like JSON data. Better to use jq like this:

jq '.id' file.json
10722

If jq is unavailable then use gnu grep:

grep -oP '"id":\K\d+' file.json
10722
anubhava
  • 761,203
  • 64
  • 569
  • 643