0

below is the json array , from each object i need to print link and name. can achieve this from shell script? I have tried using jq , but i was able to fetch only one value.

values[
{
  "Links": "https://abc/tset",
  "Dates": 1540204743643,
  "name" : test1
}
{
  "Links": "https://abc/tset",
  "Dates": 1539256093799,
  "name" : test2
}
]
  • 3
    Can you paste an example of what you have tried so far? – Lawrence Oct 23 '18 at 5:48
  • 2
    Your example isn't proper JSON. Please edit the question and either make it proper JSON, or indicate that it's really that format. In the latter case, can you rely on the line breaks always looking like this? – dirkt Oct 23 '18 at 6:07
2

Do you mean something like this?

$ jq --raw-output '.values[] | [.Links,.name] | @tsv' <<< '{"values": [{"Links": "https://abc/tset", "Dates": 1540204743643, "name": "test1"}, {"Links": "https://abc/tset", "Dates": 1539256093799, "name": "test2"}]}'
https://abc/tset    test1
https://abc/tset    test2
0

you can use this:
grep -Eoe ' "Links":([[:space:]]+[^[:space:]]+){1}' -Eoe ' "name" :([[:space:]]+[^[:space:]]+){1}'

it will find link and name and shows a word after them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.