On Fri, Mar 10, 2017 at 10:08 AM, Alexander Kapshuk <alexander.kaps...@gmail.com> wrote: > On Fri, Mar 10, 2017 at 5:05 AM, Adam Carter <adamcart...@gmail.com> wrote: >> I have one command that dumps out a number of lines of output, and i want to >> have another command run multiple times taking a single line contents as its >> argument(s) each time. From what i understand of xargs it takes all the >> piped input and runs a command once with each of the piped inputs as another >> argument. >> >> Eg. say i want to run ethtool against each active interface dumped out by; >> ifconfig | grep ^[a-zA-Z] | awk '{print $1}' >> >> Tnx >> > > As an alternative solution, you could generate the commands to run like so: > > ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { print "ethtool", $1 }' > > And then, either pipe the output of the command line above to sh, or > do this within the awk's print statement like so: > > ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { print "ethtool", $1 | "sh" }' > > Or like so: > > ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { system("ethtool", $1) }'
The last comand line should not have a comma in args to system(): ifconfig | awk -F: '$1 ~ /^[a-zA-z]/ { system("ethtool " $1) }'