1 |
On 03/09/2017 10:05 PM, Adam Carter wrote: |
2 |
> I have one command that dumps out a number of lines of output, and i want |
3 |
> to have another command run multiple times taking a single line contents as |
4 |
> its argument(s) each time. From what i understand of xargs it takes all the |
5 |
> piped input and runs a command once with each of the piped inputs as |
6 |
> another argument. |
7 |
> |
8 |
> Eg. say i want to run ethtool against each active interface dumped out by; |
9 |
> ifconfig | grep ^[a-zA-Z] | awk '{print $1}' |
10 |
> |
11 |
> Tnx |
12 |
> |
13 |
|
14 |
You can still use xargs to do this, you just need to pass "-n 1" to tell |
15 |
xargs to only use 1 argument from the input per command run (instead of |
16 |
as many as possible), like so: |
17 |
|
18 |
ifconfig | grep [^A-Za-z] | awk '{print $1}' | xargs -n 1 ethtool |
19 |
|
20 |
-- |
21 |
Jonathan Callen |