1 |
On Fri, Mar 10, 2017 at 10:08 AM, Alexander Kapshuk |
2 |
<alexander.kapshuk@×××××.com> wrote: |
3 |
> On Fri, Mar 10, 2017 at 5:05 AM, Adam Carter <adamcarter3@×××××.com> wrote: |
4 |
>> I have one command that dumps out a number of lines of output, and i want to |
5 |
>> have another command run multiple times taking a single line contents as its |
6 |
>> argument(s) each time. From what i understand of xargs it takes all the |
7 |
>> piped input and runs a command once with each of the piped inputs as another |
8 |
>> argument. |
9 |
>> |
10 |
>> Eg. say i want to run ethtool against each active interface dumped out by; |
11 |
>> ifconfig | grep ^[a-zA-Z] | awk '{print $1}' |
12 |
>> |
13 |
>> Tnx |
14 |
>> |
15 |
> |
16 |
> As an alternative solution, you could generate the commands to run like so: |
17 |
> |
18 |
> ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { print "ethtool", $1 }' |
19 |
> |
20 |
> And then, either pipe the output of the command line above to sh, or |
21 |
> do this within the awk's print statement like so: |
22 |
> |
23 |
> ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { print "ethtool", $1 | "sh" }' |
24 |
> |
25 |
> Or like so: |
26 |
> |
27 |
> ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { system("ethtool", $1) }' |
28 |
|
29 |
The last comand line should not have a comma in args to system(): |
30 |
|
31 |
ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { system("ethtool " $1) }' |