Find file json check if generated or execute

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











up vote
1
down vote

favorite












I want to find *.json2 files , check if they r executed if no execute POST.



I have



1.json2
2.json2 2.json2.ml
3.json2 3.json2.ml


I use this command



find . -type f -name '*.json2' | if [.ml]; then -exec sh -c 'curl -X POST -H "Content-Type: application/json" -d @ https://api.myweb.com/api > .ml' ;


I want to execute only the file dont have ml extension.
Thx










share|improve this question



























    up vote
    1
    down vote

    favorite












    I want to find *.json2 files , check if they r executed if no execute POST.



    I have



    1.json2
    2.json2 2.json2.ml
    3.json2 3.json2.ml


    I use this command



    find . -type f -name '*.json2' | if [.ml]; then -exec sh -c 'curl -X POST -H "Content-Type: application/json" -d @ https://api.myweb.com/api > .ml' ;


    I want to execute only the file dont have ml extension.
    Thx










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I want to find *.json2 files , check if they r executed if no execute POST.



      I have



      1.json2
      2.json2 2.json2.ml
      3.json2 3.json2.ml


      I use this command



      find . -type f -name '*.json2' | if [.ml]; then -exec sh -c 'curl -X POST -H "Content-Type: application/json" -d @ https://api.myweb.com/api > .ml' ;


      I want to execute only the file dont have ml extension.
      Thx










      share|improve this question















      I want to find *.json2 files , check if they r executed if no execute POST.



      I have



      1.json2
      2.json2 2.json2.ml
      3.json2 3.json2.ml


      I use this command



      find . -type f -name '*.json2' | if [.ml]; then -exec sh -c 'curl -X POST -H "Content-Type: application/json" -d @ https://api.myweb.com/api > .ml' ;


      I want to execute only the file dont have ml extension.
      Thx







      scripting find json






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 29 at 10:13









      Jeff Schaller

      32.7k849110




      32.7k849110










      asked Aug 29 at 2:37









      Jess

      83




      83




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          -1
          down vote



          accepted










          Have you considered using xargs?



          find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash


          As for that trailing bash, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
          I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.






          share|improve this answer




















          • It's not a trick, it's that argument that gets put into $0.
            – Kusalananda
            Aug 29 at 10:17










          • I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
            – flaysomerages
            Aug 29 at 13:44

















          up vote
          0
          down vote













          find . -type f -name '*.json2' -exec sh -c '
          for pathname; do
          [ -e "$pathname.ml" ] && continue
          curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
          done' sh +


          This would find all regular files whose filenames match the pattern *.json2 in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find, whether there's a .ml file corresponding to the pathname. If there is not, your curl command is executed.



          This could be simplified into the following if all files are located in the current directory only:



          for pathname in ./*.json2; do
          [ -e "$pathname.ml" ] && continue
          curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
          done


          Note that this is essentially exactly the same loop as in the script called by find. The only difference is that in the first example, find act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).



          Related:



          • Understanding the -exec option of `find`





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465411%2ffind-file-json-check-if-generated-or-execute%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            -1
            down vote



            accepted










            Have you considered using xargs?



            find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash


            As for that trailing bash, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
            I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.






            share|improve this answer




















            • It's not a trick, it's that argument that gets put into $0.
              – Kusalananda
              Aug 29 at 10:17










            • I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
              – flaysomerages
              Aug 29 at 13:44














            up vote
            -1
            down vote



            accepted










            Have you considered using xargs?



            find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash


            As for that trailing bash, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
            I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.






            share|improve this answer




















            • It's not a trick, it's that argument that gets put into $0.
              – Kusalananda
              Aug 29 at 10:17










            • I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
              – flaysomerages
              Aug 29 at 13:44












            up vote
            -1
            down vote



            accepted







            up vote
            -1
            down vote



            accepted






            Have you considered using xargs?



            find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash


            As for that trailing bash, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
            I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.






            share|improve this answer












            Have you considered using xargs?



            find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash


            As for that trailing bash, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
            I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 29 at 3:38









            flaysomerages

            1225




            1225











            • It's not a trick, it's that argument that gets put into $0.
              – Kusalananda
              Aug 29 at 10:17










            • I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
              – flaysomerages
              Aug 29 at 13:44
















            • It's not a trick, it's that argument that gets put into $0.
              – Kusalananda
              Aug 29 at 10:17










            • I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
              – flaysomerages
              Aug 29 at 13:44















            It's not a trick, it's that argument that gets put into $0.
            – Kusalananda
            Aug 29 at 10:17




            It's not a trick, it's that argument that gets put into $0.
            – Kusalananda
            Aug 29 at 10:17












            I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
            – flaysomerages
            Aug 29 at 13:44




            I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
            – flaysomerages
            Aug 29 at 13:44












            up vote
            0
            down vote













            find . -type f -name '*.json2' -exec sh -c '
            for pathname; do
            [ -e "$pathname.ml" ] && continue
            curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
            done' sh +


            This would find all regular files whose filenames match the pattern *.json2 in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find, whether there's a .ml file corresponding to the pathname. If there is not, your curl command is executed.



            This could be simplified into the following if all files are located in the current directory only:



            for pathname in ./*.json2; do
            [ -e "$pathname.ml" ] && continue
            curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
            done


            Note that this is essentially exactly the same loop as in the script called by find. The only difference is that in the first example, find act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).



            Related:



            • Understanding the -exec option of `find`





            share|improve this answer
























              up vote
              0
              down vote













              find . -type f -name '*.json2' -exec sh -c '
              for pathname; do
              [ -e "$pathname.ml" ] && continue
              curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
              done' sh +


              This would find all regular files whose filenames match the pattern *.json2 in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find, whether there's a .ml file corresponding to the pathname. If there is not, your curl command is executed.



              This could be simplified into the following if all files are located in the current directory only:



              for pathname in ./*.json2; do
              [ -e "$pathname.ml" ] && continue
              curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
              done


              Note that this is essentially exactly the same loop as in the script called by find. The only difference is that in the first example, find act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).



              Related:



              • Understanding the -exec option of `find`





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                find . -type f -name '*.json2' -exec sh -c '
                for pathname; do
                [ -e "$pathname.ml" ] && continue
                curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
                done' sh +


                This would find all regular files whose filenames match the pattern *.json2 in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find, whether there's a .ml file corresponding to the pathname. If there is not, your curl command is executed.



                This could be simplified into the following if all files are located in the current directory only:



                for pathname in ./*.json2; do
                [ -e "$pathname.ml" ] && continue
                curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
                done


                Note that this is essentially exactly the same loop as in the script called by find. The only difference is that in the first example, find act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).



                Related:



                • Understanding the -exec option of `find`





                share|improve this answer












                find . -type f -name '*.json2' -exec sh -c '
                for pathname; do
                [ -e "$pathname.ml" ] && continue
                curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
                done' sh +


                This would find all regular files whose filenames match the pattern *.json2 in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find, whether there's a .ml file corresponding to the pathname. If there is not, your curl command is executed.



                This could be simplified into the following if all files are located in the current directory only:



                for pathname in ./*.json2; do
                [ -e "$pathname.ml" ] && continue
                curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
                done


                Note that this is essentially exactly the same loop as in the script called by find. The only difference is that in the first example, find act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).



                Related:



                • Understanding the -exec option of `find`






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 29 at 12:37









                Kusalananda

                107k14209329




                107k14209329



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465411%2ffind-file-json-check-if-generated-or-execute%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

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

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay