How to pass arguments to a command from two files?
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
add a comment |
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
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
shell-script for
asked Feb 6 at 10:00
m6qm6q
53
53
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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 ...' _
add a comment |
You can use join
to join the two files. Then maybe xargs
, or for i in …
.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 ...' _
add a comment |
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 ...' _
add a comment |
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 ...' _
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 ...' _
answered Feb 6 at 10:16
OlorinOlorin
3,4431418
3,4431418
add a comment |
add a comment |
You can use join
to join the two files. Then maybe xargs
, or for i in …
.
add a comment |
You can use join
to join the two files. Then maybe xargs
, or for i in …
.
add a comment |
You can use join
to join the two files. Then maybe xargs
, or for i in …
.
You can use join
to join the two files. Then maybe xargs
, or for i in …
.
answered Feb 6 at 10:12
ctrl-alt-delorctrl-alt-delor
11.8k42159
11.8k42159
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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