copying files resulting from using grep into a new folder

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








up vote
0
down vote

favorite












I have a question concerning the concatenation of two processes in the terminal. I have a folder with over 50.000 files. I used grep to look for those files containing a specific term:



grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files


which gives me a huge list like this:



/var/cqp/upload/heideko/import_files/26629.vrt
/var/cqp/upload/heideko/import_files/32862.vrt


I need to copy the resulting files into a new folder. I was thinking something like:



grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | cp * bio_files/


My try might not make any sense. I'm just starting with the terminal. I just want to copy the files resulting from my grep search into a new folder called bio_files. I realised that what I get from grep is just the names of the files. But I want to use those names as input for the cp command. Any help is highly appreciated.







share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a question concerning the concatenation of two processes in the terminal. I have a folder with over 50.000 files. I used grep to look for those files containing a specific term:



    grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files


    which gives me a huge list like this:



    /var/cqp/upload/heideko/import_files/26629.vrt
    /var/cqp/upload/heideko/import_files/32862.vrt


    I need to copy the resulting files into a new folder. I was thinking something like:



    grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | cp * bio_files/


    My try might not make any sense. I'm just starting with the terminal. I just want to copy the files resulting from my grep search into a new folder called bio_files. I realised that what I get from grep is just the names of the files. But I want to use those names as input for the cp command. Any help is highly appreciated.







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a question concerning the concatenation of two processes in the terminal. I have a folder with over 50.000 files. I used grep to look for those files containing a specific term:



      grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files


      which gives me a huge list like this:



      /var/cqp/upload/heideko/import_files/26629.vrt
      /var/cqp/upload/heideko/import_files/32862.vrt


      I need to copy the resulting files into a new folder. I was thinking something like:



      grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | cp * bio_files/


      My try might not make any sense. I'm just starting with the terminal. I just want to copy the files resulting from my grep search into a new folder called bio_files. I realised that what I get from grep is just the names of the files. But I want to use those names as input for the cp command. Any help is highly appreciated.







      share|improve this question














      I have a question concerning the concatenation of two processes in the terminal. I have a folder with over 50.000 files. I used grep to look for those files containing a specific term:



      grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files


      which gives me a huge list like this:



      /var/cqp/upload/heideko/import_files/26629.vrt
      /var/cqp/upload/heideko/import_files/32862.vrt


      I need to copy the resulting files into a new folder. I was thinking something like:



      grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | cp * bio_files/


      My try might not make any sense. I'm just starting with the terminal. I just want to copy the files resulting from my grep search into a new folder called bio_files. I realised that what I get from grep is just the names of the files. But I want to use those names as input for the cp command. Any help is highly appreciated.









      share|improve this question













      share|improve this question




      share|improve this question








      edited May 15 at 16:22









      muru

      129k19271460




      129k19271460










      asked May 15 at 16:00









      Carolina Cárdenas

      31




      31




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Use xargs and the -t option of cp:



          grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs cp -t bio_files/


          If your files might have spaces in their names, then make everything null-delimited:



          grep -inrlZ "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs -0 cp -t bio_files/





          share|improve this answer




















          • Thank you. That worked! I'll read more about xargs!
            – Carolina Cárdenas
            May 15 at 16:31










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          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: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2faskubuntu.com%2fquestions%2f1036597%2fcopying-files-resulting-from-using-grep-into-a-new-folder%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          Use xargs and the -t option of cp:



          grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs cp -t bio_files/


          If your files might have spaces in their names, then make everything null-delimited:



          grep -inrlZ "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs -0 cp -t bio_files/





          share|improve this answer




















          • Thank you. That worked! I'll read more about xargs!
            – Carolina Cárdenas
            May 15 at 16:31














          up vote
          3
          down vote



          accepted










          Use xargs and the -t option of cp:



          grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs cp -t bio_files/


          If your files might have spaces in their names, then make everything null-delimited:



          grep -inrlZ "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs -0 cp -t bio_files/





          share|improve this answer




















          • Thank you. That worked! I'll read more about xargs!
            – Carolina Cárdenas
            May 15 at 16:31












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          Use xargs and the -t option of cp:



          grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs cp -t bio_files/


          If your files might have spaces in their names, then make everything null-delimited:



          grep -inrlZ "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs -0 cp -t bio_files/





          share|improve this answer












          Use xargs and the -t option of cp:



          grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs cp -t bio_files/


          If your files might have spaces in their names, then make everything null-delimited:



          grep -inrlZ "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs -0 cp -t bio_files/






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 15 at 16:11









          steeldriver

          62.2k1196164




          62.2k1196164











          • Thank you. That worked! I'll read more about xargs!
            – Carolina Cárdenas
            May 15 at 16:31
















          • Thank you. That worked! I'll read more about xargs!
            – Carolina Cárdenas
            May 15 at 16:31















          Thank you. That worked! I'll read more about xargs!
          – Carolina Cárdenas
          May 15 at 16:31




          Thank you. That worked! I'll read more about xargs!
          – Carolina Cárdenas
          May 15 at 16:31












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036597%2fcopying-files-resulting-from-using-grep-into-a-new-folder%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Which professions warranted travel in Medieval times?

          How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

          Trouble downloading packages list due to a “Hash sum mismatch” error