How to parse with Bash script? (platform MIPS)? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite













This question already has an answer here:



  • Parse JSON using Python?

    8 answers



$ curl -LNs "http://urladrescom/content.json" > content.json


content.json




"k":[

"i":1,
"n":"NAME 1",
"p":[

"b":"Event 1",
"c":"00:00",
"d":"03:00"
,

"b":"Event 2",
"c":"23:00",
"d":"00:00"

]
,

"i":2,
"n":"NAME 2",
"p":[

"b":"Event 1",
"c":"07:15",
"d":"09:15"
,

"b":"Event 2",
"c":"22:00",
"d":"23:15"
,

"b":"Event 3",
"c":"23:15",
"d":"02:30"

]
,

"i":3,
"n":"NAME 3",
"p":[

"b":"Event 1",
"c":"07:15",
"d":"09:15"
,

"b":"Event 2",
"c":"22:00",
"d":"23:15"
,

"b":"Event 3",
"c":"23:15",
"d":"02:30"

]

]



I want to get the content in "NAME 2" under Event 1,2,3 with a Bash script (grep, awk, sed, etc..) (or Python in a Bash script cmd).



I want print result :



NAME 2 Event 1 07:15 09:15
NAME 2 Event 2 22:00 23:15
NAME 2 Event 3 23:15 02:30









share|improve this question















marked as duplicate by G-Man, msp9011, Wouter Verhelst, Isaac, dhag Aug 20 at 19:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    I'd suggest using jq instead e.g. jq -r --arg name "NAME 2" '.k | select(.n==$name) | .p | [$name, .b, .c, .d] | @tsv' content.json
    – steeldriver
    Aug 19 at 23:43







  • 1




    jq is not in my system. my system platform mips only grep sed awk curl and cmd python !
    – tioma
    Aug 20 at 0:02











  • @tioma You should be able to install jq, either by using your package manager, or by compiling it yourself.
    – Kusalananda
    Aug 20 at 7:31














up vote
1
down vote

favorite













This question already has an answer here:



  • Parse JSON using Python?

    8 answers



$ curl -LNs "http://urladrescom/content.json" > content.json


content.json




"k":[

"i":1,
"n":"NAME 1",
"p":[

"b":"Event 1",
"c":"00:00",
"d":"03:00"
,

"b":"Event 2",
"c":"23:00",
"d":"00:00"

]
,

"i":2,
"n":"NAME 2",
"p":[

"b":"Event 1",
"c":"07:15",
"d":"09:15"
,

"b":"Event 2",
"c":"22:00",
"d":"23:15"
,

"b":"Event 3",
"c":"23:15",
"d":"02:30"

]
,

"i":3,
"n":"NAME 3",
"p":[

"b":"Event 1",
"c":"07:15",
"d":"09:15"
,

"b":"Event 2",
"c":"22:00",
"d":"23:15"
,

"b":"Event 3",
"c":"23:15",
"d":"02:30"

]

]



I want to get the content in "NAME 2" under Event 1,2,3 with a Bash script (grep, awk, sed, etc..) (or Python in a Bash script cmd).



I want print result :



NAME 2 Event 1 07:15 09:15
NAME 2 Event 2 22:00 23:15
NAME 2 Event 3 23:15 02:30









share|improve this question















marked as duplicate by G-Man, msp9011, Wouter Verhelst, Isaac, dhag Aug 20 at 19:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    I'd suggest using jq instead e.g. jq -r --arg name "NAME 2" '.k | select(.n==$name) | .p | [$name, .b, .c, .d] | @tsv' content.json
    – steeldriver
    Aug 19 at 23:43







  • 1




    jq is not in my system. my system platform mips only grep sed awk curl and cmd python !
    – tioma
    Aug 20 at 0:02











  • @tioma You should be able to install jq, either by using your package manager, or by compiling it yourself.
    – Kusalananda
    Aug 20 at 7:31












up vote
1
down vote

favorite









up vote
1
down vote

favorite












This question already has an answer here:



  • Parse JSON using Python?

    8 answers



$ curl -LNs "http://urladrescom/content.json" > content.json


content.json




"k":[

"i":1,
"n":"NAME 1",
"p":[

"b":"Event 1",
"c":"00:00",
"d":"03:00"
,

"b":"Event 2",
"c":"23:00",
"d":"00:00"

]
,

"i":2,
"n":"NAME 2",
"p":[

"b":"Event 1",
"c":"07:15",
"d":"09:15"
,

"b":"Event 2",
"c":"22:00",
"d":"23:15"
,

"b":"Event 3",
"c":"23:15",
"d":"02:30"

]
,

"i":3,
"n":"NAME 3",
"p":[

"b":"Event 1",
"c":"07:15",
"d":"09:15"
,

"b":"Event 2",
"c":"22:00",
"d":"23:15"
,

"b":"Event 3",
"c":"23:15",
"d":"02:30"

]

]



I want to get the content in "NAME 2" under Event 1,2,3 with a Bash script (grep, awk, sed, etc..) (or Python in a Bash script cmd).



I want print result :



NAME 2 Event 1 07:15 09:15
NAME 2 Event 2 22:00 23:15
NAME 2 Event 3 23:15 02:30









share|improve this question
















This question already has an answer here:



  • Parse JSON using Python?

    8 answers



$ curl -LNs "http://urladrescom/content.json" > content.json


content.json




"k":[

"i":1,
"n":"NAME 1",
"p":[

"b":"Event 1",
"c":"00:00",
"d":"03:00"
,

"b":"Event 2",
"c":"23:00",
"d":"00:00"

]
,

"i":2,
"n":"NAME 2",
"p":[

"b":"Event 1",
"c":"07:15",
"d":"09:15"
,

"b":"Event 2",
"c":"22:00",
"d":"23:15"
,

"b":"Event 3",
"c":"23:15",
"d":"02:30"

]
,

"i":3,
"n":"NAME 3",
"p":[

"b":"Event 1",
"c":"07:15",
"d":"09:15"
,

"b":"Event 2",
"c":"22:00",
"d":"23:15"
,

"b":"Event 3",
"c":"23:15",
"d":"02:30"

]

]



I want to get the content in "NAME 2" under Event 1,2,3 with a Bash script (grep, awk, sed, etc..) (or Python in a Bash script cmd).



I want print result :



NAME 2 Event 1 07:15 09:15
NAME 2 Event 2 22:00 23:15
NAME 2 Event 3 23:15 02:30




This question already has an answer here:



  • Parse JSON using Python?

    8 answers







awk sed grep json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 20 at 16:44









slm♦

238k65493664




238k65493664










asked Aug 19 at 23:14









tioma

134




134




marked as duplicate by G-Man, msp9011, Wouter Verhelst, Isaac, dhag Aug 20 at 19:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by G-Man, msp9011, Wouter Verhelst, Isaac, dhag Aug 20 at 19:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 2




    I'd suggest using jq instead e.g. jq -r --arg name "NAME 2" '.k | select(.n==$name) | .p | [$name, .b, .c, .d] | @tsv' content.json
    – steeldriver
    Aug 19 at 23:43







  • 1




    jq is not in my system. my system platform mips only grep sed awk curl and cmd python !
    – tioma
    Aug 20 at 0:02











  • @tioma You should be able to install jq, either by using your package manager, or by compiling it yourself.
    – Kusalananda
    Aug 20 at 7:31












  • 2




    I'd suggest using jq instead e.g. jq -r --arg name "NAME 2" '.k | select(.n==$name) | .p | [$name, .b, .c, .d] | @tsv' content.json
    – steeldriver
    Aug 19 at 23:43







  • 1




    jq is not in my system. my system platform mips only grep sed awk curl and cmd python !
    – tioma
    Aug 20 at 0:02











  • @tioma You should be able to install jq, either by using your package manager, or by compiling it yourself.
    – Kusalananda
    Aug 20 at 7:31







2




2




I'd suggest using jq instead e.g. jq -r --arg name "NAME 2" '.k | select(.n==$name) | .p | [$name, .b, .c, .d] | @tsv' content.json
– steeldriver
Aug 19 at 23:43





I'd suggest using jq instead e.g. jq -r --arg name "NAME 2" '.k | select(.n==$name) | .p | [$name, .b, .c, .d] | @tsv' content.json
– steeldriver
Aug 19 at 23:43





1




1




jq is not in my system. my system platform mips only grep sed awk curl and cmd python !
– tioma
Aug 20 at 0:02





jq is not in my system. my system platform mips only grep sed awk curl and cmd python !
– tioma
Aug 20 at 0:02













@tioma You should be able to install jq, either by using your package manager, or by compiling it yourself.
– Kusalananda
Aug 20 at 7:31




@tioma You should be able to install jq, either by using your package manager, or by compiling it yourself.
– Kusalananda
Aug 20 at 7:31










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










You can use this Python to do what you want:



$ cat parse.py
#!/bin/python

import json
#from pprint import pprint

with open('content.json') as f:
data = json.load(f)

for dict in data["k"]:
if (dict["n"] == "NAME 2"):
for elem in dict["p"]:
print(dict["n"] + ' \ ' + elem["b"] + ' \ ' + elem["c"] + ' \ ' + elem["d"])


Example



$ ./parse.py
NAME 2 Event 1 07:15 09:15
NAME 2 Event 2 22:00 23:15
NAME 2 Event 3 23:15 02:30





share|improve this answer




















  • this work thank you
    – tioma
    Aug 20 at 16:37

















up vote
0
down vote













Using the command line JSON parser jq...



There might be a shorter jq expression that does this, but this is what I came up with:



$ jq -r --arg name "NAME 2" '.|select(.n==$name).p|[$name,.]|join(" \ ")' content.json
NAME 2 Event 1 07:15 09:15
NAME 2 Event 2 22:00 23:15
NAME 2 Event 3 23:15 02:30


Or, using slightly more selective code, as suggested by steeldriver,



$ jq -r --arg name "NAME 2" '.k|select(.n==$name).p|[$name, .b, .c, .d]|join(" \ ")' content.json
NAME 2 Event 1 07:15 09:15
NAME 2 Event 2 22:00 23:15
NAME 2 Event 3 23:15 02:30


name is a jq variable whose value is passed on the command line. The jq code is doing five things:



  1. Extract the k arrays in the data that we're interested in.

  2. Select the particular array that we want to output (and the p bit from this).

  3. Create an array for outputting (since the name is not part of the data, it has to be inserted).

  4. Do output with the particular delimiter inserted.





share|improve this answer





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    You can use this Python to do what you want:



    $ cat parse.py
    #!/bin/python

    import json
    #from pprint import pprint

    with open('content.json') as f:
    data = json.load(f)

    for dict in data["k"]:
    if (dict["n"] == "NAME 2"):
    for elem in dict["p"]:
    print(dict["n"] + ' \ ' + elem["b"] + ' \ ' + elem["c"] + ' \ ' + elem["d"])


    Example



    $ ./parse.py
    NAME 2 Event 1 07:15 09:15
    NAME 2 Event 2 22:00 23:15
    NAME 2 Event 3 23:15 02:30





    share|improve this answer




















    • this work thank you
      – tioma
      Aug 20 at 16:37














    up vote
    2
    down vote



    accepted










    You can use this Python to do what you want:



    $ cat parse.py
    #!/bin/python

    import json
    #from pprint import pprint

    with open('content.json') as f:
    data = json.load(f)

    for dict in data["k"]:
    if (dict["n"] == "NAME 2"):
    for elem in dict["p"]:
    print(dict["n"] + ' \ ' + elem["b"] + ' \ ' + elem["c"] + ' \ ' + elem["d"])


    Example



    $ ./parse.py
    NAME 2 Event 1 07:15 09:15
    NAME 2 Event 2 22:00 23:15
    NAME 2 Event 3 23:15 02:30





    share|improve this answer




















    • this work thank you
      – tioma
      Aug 20 at 16:37












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    You can use this Python to do what you want:



    $ cat parse.py
    #!/bin/python

    import json
    #from pprint import pprint

    with open('content.json') as f:
    data = json.load(f)

    for dict in data["k"]:
    if (dict["n"] == "NAME 2"):
    for elem in dict["p"]:
    print(dict["n"] + ' \ ' + elem["b"] + ' \ ' + elem["c"] + ' \ ' + elem["d"])


    Example



    $ ./parse.py
    NAME 2 Event 1 07:15 09:15
    NAME 2 Event 2 22:00 23:15
    NAME 2 Event 3 23:15 02:30





    share|improve this answer












    You can use this Python to do what you want:



    $ cat parse.py
    #!/bin/python

    import json
    #from pprint import pprint

    with open('content.json') as f:
    data = json.load(f)

    for dict in data["k"]:
    if (dict["n"] == "NAME 2"):
    for elem in dict["p"]:
    print(dict["n"] + ' \ ' + elem["b"] + ' \ ' + elem["c"] + ' \ ' + elem["d"])


    Example



    $ ./parse.py
    NAME 2 Event 1 07:15 09:15
    NAME 2 Event 2 22:00 23:15
    NAME 2 Event 3 23:15 02:30






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 20 at 6:29









    slm♦

    238k65493664




    238k65493664











    • this work thank you
      – tioma
      Aug 20 at 16:37
















    • this work thank you
      – tioma
      Aug 20 at 16:37















    this work thank you
    – tioma
    Aug 20 at 16:37




    this work thank you
    – tioma
    Aug 20 at 16:37












    up vote
    0
    down vote













    Using the command line JSON parser jq...



    There might be a shorter jq expression that does this, but this is what I came up with:



    $ jq -r --arg name "NAME 2" '.|select(.n==$name).p|[$name,.]|join(" \ ")' content.json
    NAME 2 Event 1 07:15 09:15
    NAME 2 Event 2 22:00 23:15
    NAME 2 Event 3 23:15 02:30


    Or, using slightly more selective code, as suggested by steeldriver,



    $ jq -r --arg name "NAME 2" '.k|select(.n==$name).p|[$name, .b, .c, .d]|join(" \ ")' content.json
    NAME 2 Event 1 07:15 09:15
    NAME 2 Event 2 22:00 23:15
    NAME 2 Event 3 23:15 02:30


    name is a jq variable whose value is passed on the command line. The jq code is doing five things:



    1. Extract the k arrays in the data that we're interested in.

    2. Select the particular array that we want to output (and the p bit from this).

    3. Create an array for outputting (since the name is not part of the data, it has to be inserted).

    4. Do output with the particular delimiter inserted.





    share|improve this answer


























      up vote
      0
      down vote













      Using the command line JSON parser jq...



      There might be a shorter jq expression that does this, but this is what I came up with:



      $ jq -r --arg name "NAME 2" '.|select(.n==$name).p|[$name,.]|join(" \ ")' content.json
      NAME 2 Event 1 07:15 09:15
      NAME 2 Event 2 22:00 23:15
      NAME 2 Event 3 23:15 02:30


      Or, using slightly more selective code, as suggested by steeldriver,



      $ jq -r --arg name "NAME 2" '.k|select(.n==$name).p|[$name, .b, .c, .d]|join(" \ ")' content.json
      NAME 2 Event 1 07:15 09:15
      NAME 2 Event 2 22:00 23:15
      NAME 2 Event 3 23:15 02:30


      name is a jq variable whose value is passed on the command line. The jq code is doing five things:



      1. Extract the k arrays in the data that we're interested in.

      2. Select the particular array that we want to output (and the p bit from this).

      3. Create an array for outputting (since the name is not part of the data, it has to be inserted).

      4. Do output with the particular delimiter inserted.





      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        Using the command line JSON parser jq...



        There might be a shorter jq expression that does this, but this is what I came up with:



        $ jq -r --arg name "NAME 2" '.|select(.n==$name).p|[$name,.]|join(" \ ")' content.json
        NAME 2 Event 1 07:15 09:15
        NAME 2 Event 2 22:00 23:15
        NAME 2 Event 3 23:15 02:30


        Or, using slightly more selective code, as suggested by steeldriver,



        $ jq -r --arg name "NAME 2" '.k|select(.n==$name).p|[$name, .b, .c, .d]|join(" \ ")' content.json
        NAME 2 Event 1 07:15 09:15
        NAME 2 Event 2 22:00 23:15
        NAME 2 Event 3 23:15 02:30


        name is a jq variable whose value is passed on the command line. The jq code is doing five things:



        1. Extract the k arrays in the data that we're interested in.

        2. Select the particular array that we want to output (and the p bit from this).

        3. Create an array for outputting (since the name is not part of the data, it has to be inserted).

        4. Do output with the particular delimiter inserted.





        share|improve this answer














        Using the command line JSON parser jq...



        There might be a shorter jq expression that does this, but this is what I came up with:



        $ jq -r --arg name "NAME 2" '.|select(.n==$name).p|[$name,.]|join(" \ ")' content.json
        NAME 2 Event 1 07:15 09:15
        NAME 2 Event 2 22:00 23:15
        NAME 2 Event 3 23:15 02:30


        Or, using slightly more selective code, as suggested by steeldriver,



        $ jq -r --arg name "NAME 2" '.k|select(.n==$name).p|[$name, .b, .c, .d]|join(" \ ")' content.json
        NAME 2 Event 1 07:15 09:15
        NAME 2 Event 2 22:00 23:15
        NAME 2 Event 3 23:15 02:30


        name is a jq variable whose value is passed on the command line. The jq code is doing five things:



        1. Extract the k arrays in the data that we're interested in.

        2. Select the particular array that we want to output (and the p bit from this).

        3. Create an array for outputting (since the name is not part of the data, it has to be inserted).

        4. Do output with the particular delimiter inserted.






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Aug 20 at 6:47

























        answered Aug 20 at 6:24









        Kusalananda

        106k14209329




        106k14209329












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?