Home > Back-end >  xargs: how to "describe" output by input arguments
xargs: how to "describe" output by input arguments

Time:10-19

I have the following xargs command line:

$ gethosts |xargs -L1 -I% rx % some-command

where gethosts is a script to get a list of host addresses, and rx is a script to execute certain command on remote host. The output might be:

output 1
output 2
...

What I want is the command can output its argument:

host1,output1
host2,output2
...

i.e., I would like to know, for each output line, which host generated that ouput.

CodePudding user response:

To do this, you have to use option command in xargs "-c" and run sh for example to specify wich interpretor used for this command.

To print the host (without newline) the printf command will be used.

The final result looks like this command line :

gethost|xargs -L1 -I% sh -c 'printf "%, " && rx % some-command'
  • Related