How to move the files to new directory based on names in text file?

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











up vote
1
down vote

favorite












I have tar.gz files like below in a directory df:



A.tar.gz
B.tar.gz
C.tar.gz
D.tar.gz
E.tar.gz
F.tar.gz
G.tar.gz


I also have text file move.txt with following columns information:



ID Status Status2 Status3 Status4 Status5 tar sample
ID1 Negative Negative Negative Negative Negative D.tar.gz Sam1
ID2 Negative Negative Negative Negative Negative A.tar.gz Sam2
ID3 Negative Negative Negative Negative Negative C.tar.gz Sam3
ID4 Negative Negative Negative Negative Negative F.tar.gz Sam4


I want to move files in directory df to another directory based on their matching in move.txt file



I tried this way but didn't work:



for file in $(cat move.txt)
do
mv "$file" ~/destination
done


Output should be in ~/destination directory:



D.tar.gz
A.tar.gz
C.tar.gz
F.tar.gz


Looks like I'm missing the column in the text file. Any help?







share|improve this question

























    up vote
    1
    down vote

    favorite












    I have tar.gz files like below in a directory df:



    A.tar.gz
    B.tar.gz
    C.tar.gz
    D.tar.gz
    E.tar.gz
    F.tar.gz
    G.tar.gz


    I also have text file move.txt with following columns information:



    ID Status Status2 Status3 Status4 Status5 tar sample
    ID1 Negative Negative Negative Negative Negative D.tar.gz Sam1
    ID2 Negative Negative Negative Negative Negative A.tar.gz Sam2
    ID3 Negative Negative Negative Negative Negative C.tar.gz Sam3
    ID4 Negative Negative Negative Negative Negative F.tar.gz Sam4


    I want to move files in directory df to another directory based on their matching in move.txt file



    I tried this way but didn't work:



    for file in $(cat move.txt)
    do
    mv "$file" ~/destination
    done


    Output should be in ~/destination directory:



    D.tar.gz
    A.tar.gz
    C.tar.gz
    F.tar.gz


    Looks like I'm missing the column in the text file. Any help?







    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have tar.gz files like below in a directory df:



      A.tar.gz
      B.tar.gz
      C.tar.gz
      D.tar.gz
      E.tar.gz
      F.tar.gz
      G.tar.gz


      I also have text file move.txt with following columns information:



      ID Status Status2 Status3 Status4 Status5 tar sample
      ID1 Negative Negative Negative Negative Negative D.tar.gz Sam1
      ID2 Negative Negative Negative Negative Negative A.tar.gz Sam2
      ID3 Negative Negative Negative Negative Negative C.tar.gz Sam3
      ID4 Negative Negative Negative Negative Negative F.tar.gz Sam4


      I want to move files in directory df to another directory based on their matching in move.txt file



      I tried this way but didn't work:



      for file in $(cat move.txt)
      do
      mv "$file" ~/destination
      done


      Output should be in ~/destination directory:



      D.tar.gz
      A.tar.gz
      C.tar.gz
      F.tar.gz


      Looks like I'm missing the column in the text file. Any help?







      share|improve this question













      I have tar.gz files like below in a directory df:



      A.tar.gz
      B.tar.gz
      C.tar.gz
      D.tar.gz
      E.tar.gz
      F.tar.gz
      G.tar.gz


      I also have text file move.txt with following columns information:



      ID Status Status2 Status3 Status4 Status5 tar sample
      ID1 Negative Negative Negative Negative Negative D.tar.gz Sam1
      ID2 Negative Negative Negative Negative Negative A.tar.gz Sam2
      ID3 Negative Negative Negative Negative Negative C.tar.gz Sam3
      ID4 Negative Negative Negative Negative Negative F.tar.gz Sam4


      I want to move files in directory df to another directory based on their matching in move.txt file



      I tried this way but didn't work:



      for file in $(cat move.txt)
      do
      mv "$file" ~/destination
      done


      Output should be in ~/destination directory:



      D.tar.gz
      A.tar.gz
      C.tar.gz
      F.tar.gz


      Looks like I'm missing the column in the text file. Any help?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Apr 27 at 13:04









      Kiwy

      5,30743350




      5,30743350









      asked Apr 27 at 11:36









      beginner

      355




      355




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          bash + awk solution:



          for f in $(awk 'NR > 1 print $7 ' move.txt); do 
          [[ -f "$f" ]] && mv "$f" ~/destination
          done



          Or with xargs:



          awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination



          The crucial awk operation implies:




          • NR > 1 - start processing from the 2nd line (skip the 1st one as header)


          • print $7 - print the 7th field value $7 (tar column)





          share|improve this answer






























            up vote
            2
            down vote













            Answering my own question



            Inside directory "df" I gave the following command. And it worked.



            cat move.txt | xargs mv -t destination/





            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%2f440398%2fhow-to-move-the-files-to-new-directory-based-on-names-in-text-file%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
              2
              down vote



              accepted










              bash + awk solution:



              for f in $(awk 'NR > 1 print $7 ' move.txt); do 
              [[ -f "$f" ]] && mv "$f" ~/destination
              done



              Or with xargs:



              awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination



              The crucial awk operation implies:




              • NR > 1 - start processing from the 2nd line (skip the 1st one as header)


              • print $7 - print the 7th field value $7 (tar column)





              share|improve this answer



























                up vote
                2
                down vote



                accepted










                bash + awk solution:



                for f in $(awk 'NR > 1 print $7 ' move.txt); do 
                [[ -f "$f" ]] && mv "$f" ~/destination
                done



                Or with xargs:



                awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination



                The crucial awk operation implies:




                • NR > 1 - start processing from the 2nd line (skip the 1st one as header)


                • print $7 - print the 7th field value $7 (tar column)





                share|improve this answer

























                  up vote
                  2
                  down vote



                  accepted







                  up vote
                  2
                  down vote



                  accepted






                  bash + awk solution:



                  for f in $(awk 'NR > 1 print $7 ' move.txt); do 
                  [[ -f "$f" ]] && mv "$f" ~/destination
                  done



                  Or with xargs:



                  awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination



                  The crucial awk operation implies:




                  • NR > 1 - start processing from the 2nd line (skip the 1st one as header)


                  • print $7 - print the 7th field value $7 (tar column)





                  share|improve this answer















                  bash + awk solution:



                  for f in $(awk 'NR > 1 print $7 ' move.txt); do 
                  [[ -f "$f" ]] && mv "$f" ~/destination
                  done



                  Or with xargs:



                  awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination



                  The crucial awk operation implies:




                  • NR > 1 - start processing from the 2nd line (skip the 1st one as header)


                  • print $7 - print the 7th field value $7 (tar column)






                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited Apr 27 at 12:03


























                  answered Apr 27 at 11:58









                  RomanPerekhrest

                  22.4k12144




                  22.4k12144






















                      up vote
                      2
                      down vote













                      Answering my own question



                      Inside directory "df" I gave the following command. And it worked.



                      cat move.txt | xargs mv -t destination/





                      share|improve this answer

























                        up vote
                        2
                        down vote













                        Answering my own question



                        Inside directory "df" I gave the following command. And it worked.



                        cat move.txt | xargs mv -t destination/





                        share|improve this answer























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          Answering my own question



                          Inside directory "df" I gave the following command. And it worked.



                          cat move.txt | xargs mv -t destination/





                          share|improve this answer













                          Answering my own question



                          Inside directory "df" I gave the following command. And it worked.



                          cat move.txt | xargs mv -t destination/






                          share|improve this answer













                          share|improve this answer



                          share|improve this answer











                          answered Apr 27 at 12:05









                          beginner

                          355




                          355






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440398%2fhow-to-move-the-files-to-new-directory-based-on-names-in-text-file%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?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?