redirect awk exec results to another folder












0















Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end.



I plan to do this through 3,000 files. So I am testing it on a few files at the moment.



First I was able to get the content capitalized. But all output results were not redirected.



BASE="/home/dir/input/"
find "$BASE" -type f -iname "*.txt" -exec awk '{print toupper($0)}' {} +


Then I added the following, which allowed me to output to a new filename ended with "_cap.txt"



BASE="/home/dir/input/"
find "$BASE" -type f -iname "*_pv_bind_basefile.txt" -exec awk '{print toupper($0) >> (FILENAME "_cap.txt")}' {} +


The problem showed up when I try to output to a specific folder



BASE="/home/dir/input/"
OUT_FOLDER="/home/dir/output/"
find "$BASE" -type f -iname "*_pv_bind_basefile.txt" -exec awk '{print toupper($0) >> ($OUT_FOLDER FILENAME "_cap.txt")}' {} +


I got the following error message




awk: illegal field $(), name "OUT_FOLDER" input record number 1, file
/home/dir/input/TAB1.a1.001.txt source line number 1




I tried several iterations to output the files and failed miserably after a few hours...It must be some simple thing that I overlooked or not knowing how to do it. Any suggestions would be highly appreciated. Thank you.









share



























    0















    Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end.



    I plan to do this through 3,000 files. So I am testing it on a few files at the moment.



    First I was able to get the content capitalized. But all output results were not redirected.



    BASE="/home/dir/input/"
    find "$BASE" -type f -iname "*.txt" -exec awk '{print toupper($0)}' {} +


    Then I added the following, which allowed me to output to a new filename ended with "_cap.txt"



    BASE="/home/dir/input/"
    find "$BASE" -type f -iname "*_pv_bind_basefile.txt" -exec awk '{print toupper($0) >> (FILENAME "_cap.txt")}' {} +


    The problem showed up when I try to output to a specific folder



    BASE="/home/dir/input/"
    OUT_FOLDER="/home/dir/output/"
    find "$BASE" -type f -iname "*_pv_bind_basefile.txt" -exec awk '{print toupper($0) >> ($OUT_FOLDER FILENAME "_cap.txt")}' {} +


    I got the following error message




    awk: illegal field $(), name "OUT_FOLDER" input record number 1, file
    /home/dir/input/TAB1.a1.001.txt source line number 1




    I tried several iterations to output the files and failed miserably after a few hours...It must be some simple thing that I overlooked or not knowing how to do it. Any suggestions would be highly appreciated. Thank you.









    share

























      0












      0








      0








      Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end.



      I plan to do this through 3,000 files. So I am testing it on a few files at the moment.



      First I was able to get the content capitalized. But all output results were not redirected.



      BASE="/home/dir/input/"
      find "$BASE" -type f -iname "*.txt" -exec awk '{print toupper($0)}' {} +


      Then I added the following, which allowed me to output to a new filename ended with "_cap.txt"



      BASE="/home/dir/input/"
      find "$BASE" -type f -iname "*_pv_bind_basefile.txt" -exec awk '{print toupper($0) >> (FILENAME "_cap.txt")}' {} +


      The problem showed up when I try to output to a specific folder



      BASE="/home/dir/input/"
      OUT_FOLDER="/home/dir/output/"
      find "$BASE" -type f -iname "*_pv_bind_basefile.txt" -exec awk '{print toupper($0) >> ($OUT_FOLDER FILENAME "_cap.txt")}' {} +


      I got the following error message




      awk: illegal field $(), name "OUT_FOLDER" input record number 1, file
      /home/dir/input/TAB1.a1.001.txt source line number 1




      I tried several iterations to output the files and failed miserably after a few hours...It must be some simple thing that I overlooked or not knowing how to do it. Any suggestions would be highly appreciated. Thank you.









      share














      Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end.



      I plan to do this through 3,000 files. So I am testing it on a few files at the moment.



      First I was able to get the content capitalized. But all output results were not redirected.



      BASE="/home/dir/input/"
      find "$BASE" -type f -iname "*.txt" -exec awk '{print toupper($0)}' {} +


      Then I added the following, which allowed me to output to a new filename ended with "_cap.txt"



      BASE="/home/dir/input/"
      find "$BASE" -type f -iname "*_pv_bind_basefile.txt" -exec awk '{print toupper($0) >> (FILENAME "_cap.txt")}' {} +


      The problem showed up when I try to output to a specific folder



      BASE="/home/dir/input/"
      OUT_FOLDER="/home/dir/output/"
      find "$BASE" -type f -iname "*_pv_bind_basefile.txt" -exec awk '{print toupper($0) >> ($OUT_FOLDER FILENAME "_cap.txt")}' {} +


      I got the following error message




      awk: illegal field $(), name "OUT_FOLDER" input record number 1, file
      /home/dir/input/TAB1.a1.001.txt source line number 1




      I tried several iterations to output the files and failed miserably after a few hours...It must be some simple thing that I overlooked or not knowing how to do it. Any suggestions would be highly appreciated. Thank you.







      bash awk io-redirection exec





      share












      share










      share



      share










      asked 5 mins ago









      Molly_KMolly_K

      83




      83






















          0






          active

          oldest

          votes











          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508107%2fredirect-awk-exec-results-to-another-folder%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508107%2fredirect-awk-exec-results-to-another-folder%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

          CARDNET

          Boot-repair Failure: Unable to locate package grub-common:i386

          濃尾地震