Gentoo Archives: gentoo-user

From: Jonathan Callen <jcallen@g.o>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: OT: shell question, maybe xargs?
Date: Sat, 11 Mar 2017 01:15:18
Message-Id: 5ec49331-2b38-8384-3cb8-dd9fe12dd3a0@gentoo.org
In Reply to: [gentoo-user] OT: shell question, maybe xargs? by Adam Carter
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

Attachments

File name MIME type
signature.asc application/pgp-signature