use the file contents line by line and execute [closed]

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












-2















file.txt



servername1:DBNAME1:/u01/app
servername2:DBNAME2:/u01/dbs
servername3:DBNAME3:/u01/app1


I want to use above file contents line by line and execute it in shell script



command1 hostname=servername1 db=dbanme1 location=/u01/app 
command2 hostname=servername1 db=dbanme1 location=/u01/app


after the above commands it has to take the second line values and execute










share|improve this question















closed as unclear what you're asking by Jeff Schaller, Stephen Kitt, Stephen Harris, Sparhawk, jimmij Feb 6 at 9:03


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • is this a school assignment?

    – jsotola
    Jan 29 at 6:58











  • What did you try and how did that fail? There are answers here already for everything you want to do.

    – RoVo
    Jan 29 at 6:59







  • 1





    your database names in the list at the top do not match the database names in the shell script .... they do not match in more ways than one

    – jsotola
    Jan 29 at 7:01















-2















file.txt



servername1:DBNAME1:/u01/app
servername2:DBNAME2:/u01/dbs
servername3:DBNAME3:/u01/app1


I want to use above file contents line by line and execute it in shell script



command1 hostname=servername1 db=dbanme1 location=/u01/app 
command2 hostname=servername1 db=dbanme1 location=/u01/app


after the above commands it has to take the second line values and execute










share|improve this question















closed as unclear what you're asking by Jeff Schaller, Stephen Kitt, Stephen Harris, Sparhawk, jimmij Feb 6 at 9:03


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • is this a school assignment?

    – jsotola
    Jan 29 at 6:58











  • What did you try and how did that fail? There are answers here already for everything you want to do.

    – RoVo
    Jan 29 at 6:59







  • 1





    your database names in the list at the top do not match the database names in the shell script .... they do not match in more ways than one

    – jsotola
    Jan 29 at 7:01













-2












-2








-2








file.txt



servername1:DBNAME1:/u01/app
servername2:DBNAME2:/u01/dbs
servername3:DBNAME3:/u01/app1


I want to use above file contents line by line and execute it in shell script



command1 hostname=servername1 db=dbanme1 location=/u01/app 
command2 hostname=servername1 db=dbanme1 location=/u01/app


after the above commands it has to take the second line values and execute










share|improve this question
















file.txt



servername1:DBNAME1:/u01/app
servername2:DBNAME2:/u01/dbs
servername3:DBNAME3:/u01/app1


I want to use above file contents line by line and execute it in shell script



command1 hostname=servername1 db=dbanme1 location=/u01/app 
command2 hostname=servername1 db=dbanme1 location=/u01/app


after the above commands it has to take the second line values and execute







shell-script ksh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 29 at 6:59









RoVo

3,141216




3,141216










asked Jan 29 at 6:50









skppthskppth

11




11




closed as unclear what you're asking by Jeff Schaller, Stephen Kitt, Stephen Harris, Sparhawk, jimmij Feb 6 at 9:03


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Jeff Schaller, Stephen Kitt, Stephen Harris, Sparhawk, jimmij Feb 6 at 9:03


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • is this a school assignment?

    – jsotola
    Jan 29 at 6:58











  • What did you try and how did that fail? There are answers here already for everything you want to do.

    – RoVo
    Jan 29 at 6:59







  • 1





    your database names in the list at the top do not match the database names in the shell script .... they do not match in more ways than one

    – jsotola
    Jan 29 at 7:01

















  • is this a school assignment?

    – jsotola
    Jan 29 at 6:58











  • What did you try and how did that fail? There are answers here already for everything you want to do.

    – RoVo
    Jan 29 at 6:59







  • 1





    your database names in the list at the top do not match the database names in the shell script .... they do not match in more ways than one

    – jsotola
    Jan 29 at 7:01
















is this a school assignment?

– jsotola
Jan 29 at 6:58





is this a school assignment?

– jsotola
Jan 29 at 6:58













What did you try and how did that fail? There are answers here already for everything you want to do.

– RoVo
Jan 29 at 6:59






What did you try and how did that fail? There are answers here already for everything you want to do.

– RoVo
Jan 29 at 6:59





1




1





your database names in the list at the top do not match the database names in the shell script .... they do not match in more ways than one

– jsotola
Jan 29 at 7:01





your database names in the list at the top do not match the database names in the shell script .... they do not match in more ways than one

– jsotola
Jan 29 at 7:01










2 Answers
2






active

oldest

votes


















1














while IFS=':' read -r hostname db location
do
set -- hostname="$hostname" db="$db" location="$location"
command1 "$@"
command2 "$@"
done <file.txt


Or, if you need to preserve the positional parameters,



while IFS=':' read -r hostname db location
do
command1 hostname="$hostname" db="$db" location="$location"
command2 hostname="$hostname" db="$db" location="$location"
done <file.txt


Both of these would read file.txt line by line, and for each line read the three :-delimited fields into the three variables hostname, db and location. If there are more :-delimited fields on any row, these would be added onto the value of location.



Then the commands are executed.






share|improve this answer






























    0














    Using gnu parallel:



    $ parallel --colsep ":" 'command1 hostname=1 db=2 location=3; command2 hostname=1 db=2 location=3' :::: file.txt 


    For each line in file.txt the commands are excecuted. The lines get splitted by :, so that 1,2,3 get replaced by the values in the columns.



    Note that parallel start the processes in parallel. By default the number of jobs running in parallel is the number of cores. You can specify how many jobs are allowed to run in parallel with -j. If you need to keep the output in the order of the lines executed, use the -k parameter.






    share|improve this answer































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      while IFS=':' read -r hostname db location
      do
      set -- hostname="$hostname" db="$db" location="$location"
      command1 "$@"
      command2 "$@"
      done <file.txt


      Or, if you need to preserve the positional parameters,



      while IFS=':' read -r hostname db location
      do
      command1 hostname="$hostname" db="$db" location="$location"
      command2 hostname="$hostname" db="$db" location="$location"
      done <file.txt


      Both of these would read file.txt line by line, and for each line read the three :-delimited fields into the three variables hostname, db and location. If there are more :-delimited fields on any row, these would be added onto the value of location.



      Then the commands are executed.






      share|improve this answer



























        1














        while IFS=':' read -r hostname db location
        do
        set -- hostname="$hostname" db="$db" location="$location"
        command1 "$@"
        command2 "$@"
        done <file.txt


        Or, if you need to preserve the positional parameters,



        while IFS=':' read -r hostname db location
        do
        command1 hostname="$hostname" db="$db" location="$location"
        command2 hostname="$hostname" db="$db" location="$location"
        done <file.txt


        Both of these would read file.txt line by line, and for each line read the three :-delimited fields into the three variables hostname, db and location. If there are more :-delimited fields on any row, these would be added onto the value of location.



        Then the commands are executed.






        share|improve this answer

























          1












          1








          1







          while IFS=':' read -r hostname db location
          do
          set -- hostname="$hostname" db="$db" location="$location"
          command1 "$@"
          command2 "$@"
          done <file.txt


          Or, if you need to preserve the positional parameters,



          while IFS=':' read -r hostname db location
          do
          command1 hostname="$hostname" db="$db" location="$location"
          command2 hostname="$hostname" db="$db" location="$location"
          done <file.txt


          Both of these would read file.txt line by line, and for each line read the three :-delimited fields into the three variables hostname, db and location. If there are more :-delimited fields on any row, these would be added onto the value of location.



          Then the commands are executed.






          share|improve this answer













          while IFS=':' read -r hostname db location
          do
          set -- hostname="$hostname" db="$db" location="$location"
          command1 "$@"
          command2 "$@"
          done <file.txt


          Or, if you need to preserve the positional parameters,



          while IFS=':' read -r hostname db location
          do
          command1 hostname="$hostname" db="$db" location="$location"
          command2 hostname="$hostname" db="$db" location="$location"
          done <file.txt


          Both of these would read file.txt line by line, and for each line read the three :-delimited fields into the three variables hostname, db and location. If there are more :-delimited fields on any row, these would be added onto the value of location.



          Then the commands are executed.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 29 at 7:34









          KusalanandaKusalananda

          131k17248407




          131k17248407























              0














              Using gnu parallel:



              $ parallel --colsep ":" 'command1 hostname=1 db=2 location=3; command2 hostname=1 db=2 location=3' :::: file.txt 


              For each line in file.txt the commands are excecuted. The lines get splitted by :, so that 1,2,3 get replaced by the values in the columns.



              Note that parallel start the processes in parallel. By default the number of jobs running in parallel is the number of cores. You can specify how many jobs are allowed to run in parallel with -j. If you need to keep the output in the order of the lines executed, use the -k parameter.






              share|improve this answer





























                0














                Using gnu parallel:



                $ parallel --colsep ":" 'command1 hostname=1 db=2 location=3; command2 hostname=1 db=2 location=3' :::: file.txt 


                For each line in file.txt the commands are excecuted. The lines get splitted by :, so that 1,2,3 get replaced by the values in the columns.



                Note that parallel start the processes in parallel. By default the number of jobs running in parallel is the number of cores. You can specify how many jobs are allowed to run in parallel with -j. If you need to keep the output in the order of the lines executed, use the -k parameter.






                share|improve this answer



























                  0












                  0








                  0







                  Using gnu parallel:



                  $ parallel --colsep ":" 'command1 hostname=1 db=2 location=3; command2 hostname=1 db=2 location=3' :::: file.txt 


                  For each line in file.txt the commands are excecuted. The lines get splitted by :, so that 1,2,3 get replaced by the values in the columns.



                  Note that parallel start the processes in parallel. By default the number of jobs running in parallel is the number of cores. You can specify how many jobs are allowed to run in parallel with -j. If you need to keep the output in the order of the lines executed, use the -k parameter.






                  share|improve this answer















                  Using gnu parallel:



                  $ parallel --colsep ":" 'command1 hostname=1 db=2 location=3; command2 hostname=1 db=2 location=3' :::: file.txt 


                  For each line in file.txt the commands are excecuted. The lines get splitted by :, so that 1,2,3 get replaced by the values in the columns.



                  Note that parallel start the processes in parallel. By default the number of jobs running in parallel is the number of cores. You can specify how many jobs are allowed to run in parallel with -j. If you need to keep the output in the order of the lines executed, use the -k parameter.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 29 at 8:15

























                  answered Jan 29 at 8:09









                  finswimmerfinswimmer

                  55417




                  55417












                      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