1 |
On Fri, Mar 10, 2017 at 5:05 AM, Adam Carter <adamcarter3@×××××.com> wrote: |
2 |
> I have one command that dumps out a number of lines of output, and i want to |
3 |
> have another command run multiple times taking a single line contents as its |
4 |
> 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 another |
6 |
> 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 |
As an alternative solution, you could generate the commands to run like so: |
15 |
|
16 |
ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { print "ethtool", $1 }' |
17 |
|
18 |
And then, either pipe the output of the command line above to sh, or |
19 |
do this within the awk's print statement like so: |
20 |
|
21 |
ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { print "ethtool", $1 | "sh" }' |
22 |
|
23 |
Or like so: |
24 |
|
25 |
ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { system("ethtool", $1) }' |