Bash: Use exec find option by sorting two file arguments

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











up vote
4
down vote

favorite
1












Let's say I want to compare the files with the same filename between these two directories:



 /tmp/datadir/dir1/dir2/


and



 /datadir/dir1/dir2/


It is required to sort them before comparing.



I am currently in the /tmp directory, and I tried to run this find with the exec option:



find datadir -type f -exec sdiff -s <( sort ) <( sort "/" ) ;


But, it gives me an error




sort: open failed: : No such file or directory



sort: open failed: /: No such file or directory




However, the below command works fine, but the data is not sorted for proper comparison.



find data -type f -exec sdiff -s "/" ;


How can I fix this problem?







share|improve this question


























    up vote
    4
    down vote

    favorite
    1












    Let's say I want to compare the files with the same filename between these two directories:



     /tmp/datadir/dir1/dir2/


    and



     /datadir/dir1/dir2/


    It is required to sort them before comparing.



    I am currently in the /tmp directory, and I tried to run this find with the exec option:



    find datadir -type f -exec sdiff -s <( sort ) <( sort "/" ) ;


    But, it gives me an error




    sort: open failed: : No such file or directory



    sort: open failed: /: No such file or directory




    However, the below command works fine, but the data is not sorted for proper comparison.



    find data -type f -exec sdiff -s "/" ;


    How can I fix this problem?







    share|improve this question
























      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      Let's say I want to compare the files with the same filename between these two directories:



       /tmp/datadir/dir1/dir2/


      and



       /datadir/dir1/dir2/


      It is required to sort them before comparing.



      I am currently in the /tmp directory, and I tried to run this find with the exec option:



      find datadir -type f -exec sdiff -s <( sort ) <( sort "/" ) ;


      But, it gives me an error




      sort: open failed: : No such file or directory



      sort: open failed: /: No such file or directory




      However, the below command works fine, but the data is not sorted for proper comparison.



      find data -type f -exec sdiff -s "/" ;


      How can I fix this problem?







      share|improve this question














      Let's say I want to compare the files with the same filename between these two directories:



       /tmp/datadir/dir1/dir2/


      and



       /datadir/dir1/dir2/


      It is required to sort them before comparing.



      I am currently in the /tmp directory, and I tried to run this find with the exec option:



      find datadir -type f -exec sdiff -s <( sort ) <( sort "/" ) ;


      But, it gives me an error




      sort: open failed: : No such file or directory



      sort: open failed: /: No such file or directory




      However, the below command works fine, but the data is not sorted for proper comparison.



      find data -type f -exec sdiff -s "/" ;


      How can I fix this problem?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 7 at 15:41









      Peter Mortensen

      79148




      79148










      asked Aug 7 at 14:01









      Kaushik Nayak

      21316




      21316




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          10
          down vote



          accepted










          The replacement of is done by find and happens after the evaluation of the process substitution (<(…)) and such in your code.



          Using bash -c:



          find datadir -type f -exec 
          bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;


          Or to avoid running one bash instance per file:



          find datadir -type f -exec bash -c '
          for file do
          sdiff -s <( sort "$file" ) <( sort "/$file" )
          done' bash +





          share|improve this answer





























            up vote
            1
            down vote













            You could consider using the -r (recursive) option that does all the sorting and recursing for you.






            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%2f461080%2fbash-use-exec-find-option-by-sorting-two-file-arguments%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
              10
              down vote



              accepted










              The replacement of is done by find and happens after the evaluation of the process substitution (<(…)) and such in your code.



              Using bash -c:



              find datadir -type f -exec 
              bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;


              Or to avoid running one bash instance per file:



              find datadir -type f -exec bash -c '
              for file do
              sdiff -s <( sort "$file" ) <( sort "/$file" )
              done' bash +





              share|improve this answer


























                up vote
                10
                down vote



                accepted










                The replacement of is done by find and happens after the evaluation of the process substitution (<(…)) and such in your code.



                Using bash -c:



                find datadir -type f -exec 
                bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;


                Or to avoid running one bash instance per file:



                find datadir -type f -exec bash -c '
                for file do
                sdiff -s <( sort "$file" ) <( sort "/$file" )
                done' bash +





                share|improve this answer
























                  up vote
                  10
                  down vote



                  accepted







                  up vote
                  10
                  down vote



                  accepted






                  The replacement of is done by find and happens after the evaluation of the process substitution (<(…)) and such in your code.



                  Using bash -c:



                  find datadir -type f -exec 
                  bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;


                  Or to avoid running one bash instance per file:



                  find datadir -type f -exec bash -c '
                  for file do
                  sdiff -s <( sort "$file" ) <( sort "/$file" )
                  done' bash +





                  share|improve this answer














                  The replacement of is done by find and happens after the evaluation of the process substitution (<(…)) and such in your code.



                  Using bash -c:



                  find datadir -type f -exec 
                  bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash ;


                  Or to avoid running one bash instance per file:



                  find datadir -type f -exec bash -c '
                  for file do
                  sdiff -s <( sort "$file" ) <( sort "/$file" )
                  done' bash +






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 7 at 14:17









                  Stéphane Chazelas

                  282k53520854




                  282k53520854










                  answered Aug 7 at 14:06









                  phk

                  3,80852147




                  3,80852147






















                      up vote
                      1
                      down vote













                      You could consider using the -r (recursive) option that does all the sorting and recursing for you.






                      share|improve this answer
























                        up vote
                        1
                        down vote













                        You could consider using the -r (recursive) option that does all the sorting and recursing for you.






                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          You could consider using the -r (recursive) option that does all the sorting and recursing for you.






                          share|improve this answer












                          You could consider using the -r (recursive) option that does all the sorting and recursing for you.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 7 at 17:42









                          RalfFriedl

                          2,8451519




                          2,8451519






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461080%2fbash-use-exec-find-option-by-sorting-two-file-arguments%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery