Adding string from .txt file into a command – for macro

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











up vote
1
down vote

favorite












I am processing multiple file which are saved as



N.YMDH.U.A.1.SAC 
N.YMDH.U.D.2.SAC
N.YMDH.U.E.3.SAC


and so on...

I also have a .txt file which looks as follows named YMDH_arrival_time.txt



N.YMDH.U.A.1.SAC 5.000 7.000 
N.YMDH.U.D.2.SAC 7.321 4.313
N.YMDH.U.E.3.SAC 3.243 7.876


and so on ....

I want to write a script so, if the file name matches $1, then, do a command on the file which involves the input of $2 of the same row.




What I've been attempting

#### I want the $file to be read 1 by 1 so temp_file.txt is only 1 row long then the same file is read later and the value from the .txt file can be added then the process repeated ect.



for file in /Documents/Scaling/YMDH/*.SAC do;

awk '{$1 ~ /$file/ print $1 $2 $3' /Documents/Scaling/YMDH_arrival_time.txt > temp_file.txt

#### in hope to find the row which matches and print that row into a new txt file

SAC <<EOF

r $file
CHNDHR T (I want to put the value of $2 of temp_file.txt here)
w $file.done
quit
EOF
done



any help will be appreciated or an alternate method. Thanks







share|improve this question


























    up vote
    1
    down vote

    favorite












    I am processing multiple file which are saved as



    N.YMDH.U.A.1.SAC 
    N.YMDH.U.D.2.SAC
    N.YMDH.U.E.3.SAC


    and so on...

    I also have a .txt file which looks as follows named YMDH_arrival_time.txt



    N.YMDH.U.A.1.SAC 5.000 7.000 
    N.YMDH.U.D.2.SAC 7.321 4.313
    N.YMDH.U.E.3.SAC 3.243 7.876


    and so on ....

    I want to write a script so, if the file name matches $1, then, do a command on the file which involves the input of $2 of the same row.




    What I've been attempting

    #### I want the $file to be read 1 by 1 so temp_file.txt is only 1 row long then the same file is read later and the value from the .txt file can be added then the process repeated ect.



    for file in /Documents/Scaling/YMDH/*.SAC do;

    awk '{$1 ~ /$file/ print $1 $2 $3' /Documents/Scaling/YMDH_arrival_time.txt > temp_file.txt

    #### in hope to find the row which matches and print that row into a new txt file

    SAC <<EOF

    r $file
    CHNDHR T (I want to put the value of $2 of temp_file.txt here)
    w $file.done
    quit
    EOF
    done



    any help will be appreciated or an alternate method. Thanks







    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am processing multiple file which are saved as



      N.YMDH.U.A.1.SAC 
      N.YMDH.U.D.2.SAC
      N.YMDH.U.E.3.SAC


      and so on...

      I also have a .txt file which looks as follows named YMDH_arrival_time.txt



      N.YMDH.U.A.1.SAC 5.000 7.000 
      N.YMDH.U.D.2.SAC 7.321 4.313
      N.YMDH.U.E.3.SAC 3.243 7.876


      and so on ....

      I want to write a script so, if the file name matches $1, then, do a command on the file which involves the input of $2 of the same row.




      What I've been attempting

      #### I want the $file to be read 1 by 1 so temp_file.txt is only 1 row long then the same file is read later and the value from the .txt file can be added then the process repeated ect.



      for file in /Documents/Scaling/YMDH/*.SAC do;

      awk '{$1 ~ /$file/ print $1 $2 $3' /Documents/Scaling/YMDH_arrival_time.txt > temp_file.txt

      #### in hope to find the row which matches and print that row into a new txt file

      SAC <<EOF

      r $file
      CHNDHR T (I want to put the value of $2 of temp_file.txt here)
      w $file.done
      quit
      EOF
      done



      any help will be appreciated or an alternate method. Thanks







      share|improve this question














      I am processing multiple file which are saved as



      N.YMDH.U.A.1.SAC 
      N.YMDH.U.D.2.SAC
      N.YMDH.U.E.3.SAC


      and so on...

      I also have a .txt file which looks as follows named YMDH_arrival_time.txt



      N.YMDH.U.A.1.SAC 5.000 7.000 
      N.YMDH.U.D.2.SAC 7.321 4.313
      N.YMDH.U.E.3.SAC 3.243 7.876


      and so on ....

      I want to write a script so, if the file name matches $1, then, do a command on the file which involves the input of $2 of the same row.




      What I've been attempting

      #### I want the $file to be read 1 by 1 so temp_file.txt is only 1 row long then the same file is read later and the value from the .txt file can be added then the process repeated ect.



      for file in /Documents/Scaling/YMDH/*.SAC do;

      awk '{$1 ~ /$file/ print $1 $2 $3' /Documents/Scaling/YMDH_arrival_time.txt > temp_file.txt

      #### in hope to find the row which matches and print that row into a new txt file

      SAC <<EOF

      r $file
      CHNDHR T (I want to put the value of $2 of temp_file.txt here)
      w $file.done
      quit
      EOF
      done



      any help will be appreciated or an alternate method. Thanks









      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 15 '17 at 23:00

























      asked Oct 15 '17 at 20:55









      J.DOE

      62




      62




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          If your YMDH_arrival_time.txt file has fixed format <string> <number> <number> - it's enough to use the following grep + cat approach:



          grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt





          share|improve this answer



























            up vote
            0
            down vote













            To fit your existing approach you'd just use



            variable=$(cat temp_file.txt)



            However check comments on RomanPerekhrest's approach.






            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%2f398281%2fadding-string-from-txt-file-into-a-command-for-macro%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













              If your YMDH_arrival_time.txt file has fixed format <string> <number> <number> - it's enough to use the following grep + cat approach:



              grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt





              share|improve this answer
























                up vote
                2
                down vote













                If your YMDH_arrival_time.txt file has fixed format <string> <number> <number> - it's enough to use the following grep + cat approach:



                grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt





                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  If your YMDH_arrival_time.txt file has fixed format <string> <number> <number> - it's enough to use the following grep + cat approach:



                  grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt





                  share|improve this answer












                  If your YMDH_arrival_time.txt file has fixed format <string> <number> <number> - it's enough to use the following grep + cat approach:



                  grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 15 '17 at 21:10









                  RomanPerekhrest

                  22.5k12145




                  22.5k12145






















                      up vote
                      0
                      down vote













                      To fit your existing approach you'd just use



                      variable=$(cat temp_file.txt)



                      However check comments on RomanPerekhrest's approach.






                      share|improve this answer
























                        up vote
                        0
                        down vote













                        To fit your existing approach you'd just use



                        variable=$(cat temp_file.txt)



                        However check comments on RomanPerekhrest's approach.






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          To fit your existing approach you'd just use



                          variable=$(cat temp_file.txt)



                          However check comments on RomanPerekhrest's approach.






                          share|improve this answer












                          To fit your existing approach you'd just use



                          variable=$(cat temp_file.txt)



                          However check comments on RomanPerekhrest's approach.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Oct 16 '17 at 1:13









                          jdwolf

                          2,392116




                          2,392116



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398281%2fadding-string-from-txt-file-into-a-command-for-macro%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?

                              Christian Cage

                              How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?