How to pass arguments to a command from two files?

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












0















I'm trying to replicate the setup of 50 printers from one server to another server.
Command:



lpadmin -p printer_name -v printer_ip -E and some more parameters.



I have the printer names in one text file and the printer IPs in another text file.



Printername.txt contains name of printers in separate lines



Printerip.txt contains ip of same printers in separate lines



I want to pass the printer name and printer ip from these two files as an argument to the command mentioned above.



I know how to do it for 1 parameter i.e by using
For i in cat file but I'm not able to do it with two files.










share|improve this question


























    0















    I'm trying to replicate the setup of 50 printers from one server to another server.
    Command:



    lpadmin -p printer_name -v printer_ip -E and some more parameters.



    I have the printer names in one text file and the printer IPs in another text file.



    Printername.txt contains name of printers in separate lines



    Printerip.txt contains ip of same printers in separate lines



    I want to pass the printer name and printer ip from these two files as an argument to the command mentioned above.



    I know how to do it for 1 parameter i.e by using
    For i in cat file but I'm not able to do it with two files.










    share|improve this question
























      0












      0








      0








      I'm trying to replicate the setup of 50 printers from one server to another server.
      Command:



      lpadmin -p printer_name -v printer_ip -E and some more parameters.



      I have the printer names in one text file and the printer IPs in another text file.



      Printername.txt contains name of printers in separate lines



      Printerip.txt contains ip of same printers in separate lines



      I want to pass the printer name and printer ip from these two files as an argument to the command mentioned above.



      I know how to do it for 1 parameter i.e by using
      For i in cat file but I'm not able to do it with two files.










      share|improve this question














      I'm trying to replicate the setup of 50 printers from one server to another server.
      Command:



      lpadmin -p printer_name -v printer_ip -E and some more parameters.



      I have the printer names in one text file and the printer IPs in another text file.



      Printername.txt contains name of printers in separate lines



      Printerip.txt contains ip of same printers in separate lines



      I want to pass the printer name and printer ip from these two files as an argument to the command mentioned above.



      I know how to do it for 1 parameter i.e by using
      For i in cat file but I'm not able to do it with two files.







      shell-script for






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 6 at 10:00









      m6qm6q

      53




      53




















          2 Answers
          2






          active

          oldest

          votes


















          0














          You can take one line each from each file using paste:



          paste Printername.txt Printerip.txt


          Then use awk to insert the option arguments in that:



          paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."'


          And finally use xargs to use this as arguments for the command:



          paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."' | 
          xargs -L1 lpadmin


          -L1 lets xargs use one line of input for each run of the command. It will do some splitting, so -p, the printer name etc. are passed as separate arguments. This works best of the printer names don't have whitespace or other special characters in them.



          Alternatively, you can use sh with xargs to position the input as arguments:



          paste -d 'n' Printername.txt Printerip.txt | xargs -d 'n' -n2 sh -c 'lpadmin -p "$1" -v "$2" -E ...' _





          share|improve this answer






























            0














            You can use join to join the two files. Then maybe xargs, or for i in ….






            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',
              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%2f499004%2fhow-to-pass-arguments-to-a-command-from-two-files%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              You can take one line each from each file using paste:



              paste Printername.txt Printerip.txt


              Then use awk to insert the option arguments in that:



              paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."'


              And finally use xargs to use this as arguments for the command:



              paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."' | 
              xargs -L1 lpadmin


              -L1 lets xargs use one line of input for each run of the command. It will do some splitting, so -p, the printer name etc. are passed as separate arguments. This works best of the printer names don't have whitespace or other special characters in them.



              Alternatively, you can use sh with xargs to position the input as arguments:



              paste -d 'n' Printername.txt Printerip.txt | xargs -d 'n' -n2 sh -c 'lpadmin -p "$1" -v "$2" -E ...' _





              share|improve this answer



























                0














                You can take one line each from each file using paste:



                paste Printername.txt Printerip.txt


                Then use awk to insert the option arguments in that:



                paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."'


                And finally use xargs to use this as arguments for the command:



                paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."' | 
                xargs -L1 lpadmin


                -L1 lets xargs use one line of input for each run of the command. It will do some splitting, so -p, the printer name etc. are passed as separate arguments. This works best of the printer names don't have whitespace or other special characters in them.



                Alternatively, you can use sh with xargs to position the input as arguments:



                paste -d 'n' Printername.txt Printerip.txt | xargs -d 'n' -n2 sh -c 'lpadmin -p "$1" -v "$2" -E ...' _





                share|improve this answer

























                  0












                  0








                  0







                  You can take one line each from each file using paste:



                  paste Printername.txt Printerip.txt


                  Then use awk to insert the option arguments in that:



                  paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."'


                  And finally use xargs to use this as arguments for the command:



                  paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."' | 
                  xargs -L1 lpadmin


                  -L1 lets xargs use one line of input for each run of the command. It will do some splitting, so -p, the printer name etc. are passed as separate arguments. This works best of the printer names don't have whitespace or other special characters in them.



                  Alternatively, you can use sh with xargs to position the input as arguments:



                  paste -d 'n' Printername.txt Printerip.txt | xargs -d 'n' -n2 sh -c 'lpadmin -p "$1" -v "$2" -E ...' _





                  share|improve this answer













                  You can take one line each from each file using paste:



                  paste Printername.txt Printerip.txt


                  Then use awk to insert the option arguments in that:



                  paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."'


                  And finally use xargs to use this as arguments for the command:



                  paste Printername.txt Printerip.txt | awk 'print "-p", $1, "-v", $2, "-E ..."' | 
                  xargs -L1 lpadmin


                  -L1 lets xargs use one line of input for each run of the command. It will do some splitting, so -p, the printer name etc. are passed as separate arguments. This works best of the printer names don't have whitespace or other special characters in them.



                  Alternatively, you can use sh with xargs to position the input as arguments:



                  paste -d 'n' Printername.txt Printerip.txt | xargs -d 'n' -n2 sh -c 'lpadmin -p "$1" -v "$2" -E ...' _






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 6 at 10:16









                  OlorinOlorin

                  3,4431418




                  3,4431418























                      0














                      You can use join to join the two files. Then maybe xargs, or for i in ….






                      share|improve this answer



























                        0














                        You can use join to join the two files. Then maybe xargs, or for i in ….






                        share|improve this answer

























                          0












                          0








                          0







                          You can use join to join the two files. Then maybe xargs, or for i in ….






                          share|improve this answer













                          You can use join to join the two files. Then maybe xargs, or for i in ….







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 6 at 10:12









                          ctrl-alt-delorctrl-alt-delor

                          11.8k42159




                          11.8k42159



























                              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%2f499004%2fhow-to-pass-arguments-to-a-command-from-two-files%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

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?