Finding all the JSONS file in directory and combining it in array in bash











up vote
2
down vote

favorite












i wanna find all the json files file specific directory and combine it one parent result that will contain all the result data



I am trying this



 find .  -name *data.json | tee result.json


It is finding all the data but it is saving its path in result.json,how can i get the data inside all the file and get a combine JSON of all result



this command is saving a result.json file which look like this



./17-10-2018/ghatkopar/17-18/data.json
./17-10-2018/ghatkopar/18-19/data.json
./17-10-2018/ghatkopar/10-11/data.json
./17-10-2018/ghatkopar/11-12/data.json
./17-10-2018/ghatkopar/15-16/data.json
./17-10-2018/ghatkopar/19-20/data.json
./17-10-2018/ghatkopar/14-15/data.json
./17-10-2018/ghatkopar/12-13/data.json
./17-10-2018/ghatkopar/20-21/data.json
./17-10-2018/mulund-west/16-17/data.json
./17-10-2018/mulund-west/21-22/data.json
./17-10-2018/mulund-west/13-14/data.json
./17-10-2018/mulund-west/data.json
./17-10-2018/mulund-west/17-18/data.json
./17-10-2018/mulund-west/18-19/data.json
./17-10-2018/mulund-west/10-11/data.json
./17-10-2018/mulund-west/11-12/data.json
./17-10-2018/mulund-west/15-16/data.json
./17-10-2018/mulund-west/19-20/data.json
./17-10-2018/mulund-west/14-15/data.json
./17-10-2018/mulund-west/12-13/data.json
./17-10-2018/mulund-west/20-21/data.json
./17-10-2018/bhandup/16-17/data.json
./17-10-2018/bhandup/21-22/data.json
./17-10-2018/bhandup/13-14/data.json
./17-10-2018/bhandup/data.json
./17-10-2018/bhandup/17-18/data.json
./17-10-2018/bhandup/18-19/data.json
./17-10-2018/bhandup/10-11/data.json
./17-10-2018/bhandup/11-12/data.json
./17-10-2018/bhandup/15-16/data.json









share|improve this question









New contributor




Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • It's not clear to me what you want result.json to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
    – ruakh
    3 hours ago










  • yeah,i wanna wrap it in array
    – Anurag Mishra
    3 hours ago










  • Could you not just save the results from find into an array?
    – RoadRunner
    2 hours ago















up vote
2
down vote

favorite












i wanna find all the json files file specific directory and combine it one parent result that will contain all the result data



I am trying this



 find .  -name *data.json | tee result.json


It is finding all the data but it is saving its path in result.json,how can i get the data inside all the file and get a combine JSON of all result



this command is saving a result.json file which look like this



./17-10-2018/ghatkopar/17-18/data.json
./17-10-2018/ghatkopar/18-19/data.json
./17-10-2018/ghatkopar/10-11/data.json
./17-10-2018/ghatkopar/11-12/data.json
./17-10-2018/ghatkopar/15-16/data.json
./17-10-2018/ghatkopar/19-20/data.json
./17-10-2018/ghatkopar/14-15/data.json
./17-10-2018/ghatkopar/12-13/data.json
./17-10-2018/ghatkopar/20-21/data.json
./17-10-2018/mulund-west/16-17/data.json
./17-10-2018/mulund-west/21-22/data.json
./17-10-2018/mulund-west/13-14/data.json
./17-10-2018/mulund-west/data.json
./17-10-2018/mulund-west/17-18/data.json
./17-10-2018/mulund-west/18-19/data.json
./17-10-2018/mulund-west/10-11/data.json
./17-10-2018/mulund-west/11-12/data.json
./17-10-2018/mulund-west/15-16/data.json
./17-10-2018/mulund-west/19-20/data.json
./17-10-2018/mulund-west/14-15/data.json
./17-10-2018/mulund-west/12-13/data.json
./17-10-2018/mulund-west/20-21/data.json
./17-10-2018/bhandup/16-17/data.json
./17-10-2018/bhandup/21-22/data.json
./17-10-2018/bhandup/13-14/data.json
./17-10-2018/bhandup/data.json
./17-10-2018/bhandup/17-18/data.json
./17-10-2018/bhandup/18-19/data.json
./17-10-2018/bhandup/10-11/data.json
./17-10-2018/bhandup/11-12/data.json
./17-10-2018/bhandup/15-16/data.json









share|improve this question









New contributor




Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • It's not clear to me what you want result.json to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
    – ruakh
    3 hours ago










  • yeah,i wanna wrap it in array
    – Anurag Mishra
    3 hours ago










  • Could you not just save the results from find into an array?
    – RoadRunner
    2 hours ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











i wanna find all the json files file specific directory and combine it one parent result that will contain all the result data



I am trying this



 find .  -name *data.json | tee result.json


It is finding all the data but it is saving its path in result.json,how can i get the data inside all the file and get a combine JSON of all result



this command is saving a result.json file which look like this



./17-10-2018/ghatkopar/17-18/data.json
./17-10-2018/ghatkopar/18-19/data.json
./17-10-2018/ghatkopar/10-11/data.json
./17-10-2018/ghatkopar/11-12/data.json
./17-10-2018/ghatkopar/15-16/data.json
./17-10-2018/ghatkopar/19-20/data.json
./17-10-2018/ghatkopar/14-15/data.json
./17-10-2018/ghatkopar/12-13/data.json
./17-10-2018/ghatkopar/20-21/data.json
./17-10-2018/mulund-west/16-17/data.json
./17-10-2018/mulund-west/21-22/data.json
./17-10-2018/mulund-west/13-14/data.json
./17-10-2018/mulund-west/data.json
./17-10-2018/mulund-west/17-18/data.json
./17-10-2018/mulund-west/18-19/data.json
./17-10-2018/mulund-west/10-11/data.json
./17-10-2018/mulund-west/11-12/data.json
./17-10-2018/mulund-west/15-16/data.json
./17-10-2018/mulund-west/19-20/data.json
./17-10-2018/mulund-west/14-15/data.json
./17-10-2018/mulund-west/12-13/data.json
./17-10-2018/mulund-west/20-21/data.json
./17-10-2018/bhandup/16-17/data.json
./17-10-2018/bhandup/21-22/data.json
./17-10-2018/bhandup/13-14/data.json
./17-10-2018/bhandup/data.json
./17-10-2018/bhandup/17-18/data.json
./17-10-2018/bhandup/18-19/data.json
./17-10-2018/bhandup/10-11/data.json
./17-10-2018/bhandup/11-12/data.json
./17-10-2018/bhandup/15-16/data.json









share|improve this question









New contributor




Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











i wanna find all the json files file specific directory and combine it one parent result that will contain all the result data



I am trying this



 find .  -name *data.json | tee result.json


It is finding all the data but it is saving its path in result.json,how can i get the data inside all the file and get a combine JSON of all result



this command is saving a result.json file which look like this



./17-10-2018/ghatkopar/17-18/data.json
./17-10-2018/ghatkopar/18-19/data.json
./17-10-2018/ghatkopar/10-11/data.json
./17-10-2018/ghatkopar/11-12/data.json
./17-10-2018/ghatkopar/15-16/data.json
./17-10-2018/ghatkopar/19-20/data.json
./17-10-2018/ghatkopar/14-15/data.json
./17-10-2018/ghatkopar/12-13/data.json
./17-10-2018/ghatkopar/20-21/data.json
./17-10-2018/mulund-west/16-17/data.json
./17-10-2018/mulund-west/21-22/data.json
./17-10-2018/mulund-west/13-14/data.json
./17-10-2018/mulund-west/data.json
./17-10-2018/mulund-west/17-18/data.json
./17-10-2018/mulund-west/18-19/data.json
./17-10-2018/mulund-west/10-11/data.json
./17-10-2018/mulund-west/11-12/data.json
./17-10-2018/mulund-west/15-16/data.json
./17-10-2018/mulund-west/19-20/data.json
./17-10-2018/mulund-west/14-15/data.json
./17-10-2018/mulund-west/12-13/data.json
./17-10-2018/mulund-west/20-21/data.json
./17-10-2018/bhandup/16-17/data.json
./17-10-2018/bhandup/21-22/data.json
./17-10-2018/bhandup/13-14/data.json
./17-10-2018/bhandup/data.json
./17-10-2018/bhandup/17-18/data.json
./17-10-2018/bhandup/18-19/data.json
./17-10-2018/bhandup/10-11/data.json
./17-10-2018/bhandup/11-12/data.json
./17-10-2018/bhandup/15-16/data.json






linux bash find command






share|improve this question









New contributor




Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 3 hours ago





















New contributor




Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









Anurag Mishra

112




112




New contributor




Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Anurag Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • It's not clear to me what you want result.json to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
    – ruakh
    3 hours ago










  • yeah,i wanna wrap it in array
    – Anurag Mishra
    3 hours ago










  • Could you not just save the results from find into an array?
    – RoadRunner
    2 hours ago


















  • It's not clear to me what you want result.json to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
    – ruakh
    3 hours ago










  • yeah,i wanna wrap it in array
    – Anurag Mishra
    3 hours ago










  • Could you not just save the results from find into an array?
    – RoadRunner
    2 hours ago
















It's not clear to me what you want result.json to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
– ruakh
3 hours ago




It's not clear to me what you want result.json to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
– ruakh
3 hours ago












yeah,i wanna wrap it in array
– Anurag Mishra
3 hours ago




yeah,i wanna wrap it in array
– Anurag Mishra
3 hours ago












Could you not just save the results from find into an array?
– RoadRunner
2 hours ago




Could you not just save the results from find into an array?
– RoadRunner
2 hours ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













You need to cat each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:



#! /bin/bash
printf [
separator=""
find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
printf $separator
separator=,
cat "$j"
done
printf ]





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370494%2ffinding-all-the-jsons-file-in-directory-and-combining-it-in-array-in-bash%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    You need to cat each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:



    #! /bin/bash
    printf [
    separator=""
    find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
    printf $separator
    separator=,
    cat "$j"
    done
    printf ]





    share|improve this answer

























      up vote
      0
      down vote













      You need to cat each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:



      #! /bin/bash
      printf [
      separator=""
      find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
      printf $separator
      separator=,
      cat "$j"
      done
      printf ]





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        You need to cat each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:



        #! /bin/bash
        printf [
        separator=""
        find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
        printf $separator
        separator=,
        cat "$j"
        done
        printf ]





        share|improve this answer












        You need to cat each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:



        #! /bin/bash
        printf [
        separator=""
        find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
        printf $separator
        separator=,
        cat "$j"
        done
        printf ]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 3 hours ago









        choroba

        151k14138199




        151k14138199






















            Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.













            Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.












            Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370494%2ffinding-all-the-jsons-file-in-directory-and-combining-it-in-array-in-bash%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Volksrepublik China

            How to test boost logger output in unit testing?

            Write to the output between two pipeline