how to use shell's for loop to change two files

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











up vote
-1
down vote

favorite












I would like to use for loop to create files in shell.
I have 3 files named sensor_1.nmf, sensor_2.nmf, sensor_3.nmf, and I want to use a software to create another 7 python files for each files above,i.e.,
Using sensor_1 creates 7 python files like r_sensor_1.py, r_sensor_2.py ...
My code is below:



for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done


But it can not work. Could somebody help me? Thanks.







share|improve this question


















  • 1




    Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
    – Raman Sailopal
    Jan 22 at 14:43










  • idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
    – Murphy
    Jan 22 at 15:22














up vote
-1
down vote

favorite












I would like to use for loop to create files in shell.
I have 3 files named sensor_1.nmf, sensor_2.nmf, sensor_3.nmf, and I want to use a software to create another 7 python files for each files above,i.e.,
Using sensor_1 creates 7 python files like r_sensor_1.py, r_sensor_2.py ...
My code is below:



for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done


But it can not work. Could somebody help me? Thanks.







share|improve this question


















  • 1




    Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
    – Raman Sailopal
    Jan 22 at 14:43










  • idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
    – Murphy
    Jan 22 at 15:22












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I would like to use for loop to create files in shell.
I have 3 files named sensor_1.nmf, sensor_2.nmf, sensor_3.nmf, and I want to use a software to create another 7 python files for each files above,i.e.,
Using sensor_1 creates 7 python files like r_sensor_1.py, r_sensor_2.py ...
My code is below:



for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done


But it can not work. Could somebody help me? Thanks.







share|improve this question














I would like to use for loop to create files in shell.
I have 3 files named sensor_1.nmf, sensor_2.nmf, sensor_3.nmf, and I want to use a software to create another 7 python files for each files above,i.e.,
Using sensor_1 creates 7 python files like r_sensor_1.py, r_sensor_2.py ...
My code is below:



for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done


But it can not work. Could somebody help me? Thanks.









share|improve this question













share|improve this question




share|improve this question








edited Jan 22 at 15:35









Murphy

1,7471517




1,7471517










asked Jan 22 at 14:25









user271856

1




1







  • 1




    Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
    – Raman Sailopal
    Jan 22 at 14:43










  • idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
    – Murphy
    Jan 22 at 15:22












  • 1




    Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
    – Raman Sailopal
    Jan 22 at 14:43










  • idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
    – Murphy
    Jan 22 at 15:22







1




1




Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
– Raman Sailopal
Jan 22 at 14:43




Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
– Raman Sailopal
Jan 22 at 14:43












idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
– Murphy
Jan 22 at 15:22




idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
– Murphy
Jan 22 at 15:22










2 Answers
2






active

oldest

votes

















up vote
0
down vote













You can use brace expansion as opposed to iterating through the for loops.



nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p 
r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7





share|improve this answer



























    up vote
    0
    down vote













    At your inner for-loop you are missing the "do".



    for j in 1 2 3
    do
    for k in 1 2 3 4 5 6 7
    do
    nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
    done
    done





    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%2f418872%2fhow-to-use-shells-for-loop-to-change-two-files%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
      0
      down vote













      You can use brace expansion as opposed to iterating through the for loops.



      nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p 
      r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7





      share|improve this answer
























        up vote
        0
        down vote













        You can use brace expansion as opposed to iterating through the for loops.



        nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p 
        r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7





        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          You can use brace expansion as opposed to iterating through the for loops.



          nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p 
          r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7





          share|improve this answer












          You can use brace expansion as opposed to iterating through the for loops.



          nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p 
          r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 22 at 14:57









          Jaken551

          1678




          1678






















              up vote
              0
              down vote













              At your inner for-loop you are missing the "do".



              for j in 1 2 3
              do
              for k in 1 2 3 4 5 6 7
              do
              nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
              done
              done





              share|improve this answer
























                up vote
                0
                down vote













                At your inner for-loop you are missing the "do".



                for j in 1 2 3
                do
                for k in 1 2 3 4 5 6 7
                do
                nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
                done
                done





                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  At your inner for-loop you are missing the "do".



                  for j in 1 2 3
                  do
                  for k in 1 2 3 4 5 6 7
                  do
                  nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
                  done
                  done





                  share|improve this answer












                  At your inner for-loop you are missing the "do".



                  for j in 1 2 3
                  do
                  for k in 1 2 3 4 5 6 7
                  do
                  nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
                  done
                  done






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 26 at 9:03









                  KarlG

                  113




                  113






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418872%2fhow-to-use-shells-for-loop-to-change-two-files%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?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay