This is a discussion on feeding a series of input args to a command that only takes one within the Linux General forums, part of the Linux Forums category; Sometimes I have commands that are designed only to process a single input argument but I want to call them ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Sometimes I have commands that are designed only to process a single
input argument but I want to call them repeatedly on a list. For example I generate a command line pipe that outputs a list of ip addresses: cmd1 | cmd2 | tr '\n' '\t' 11.0.0.21 11.0.0.176 11.0.0.191 To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex <ip address> Is there a command line metaphor to feed a command one arg at a time repeatedly. I guess I could use a for loop but that's somewhat unweildly on the command line. -- Rahul |
|
|||
|
On 2008-05-01, Rahul <nospam@nospam.invalid> wrote:
> To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex ><ip address> > > Is there a command line metaphor to feed a command one arg at a time > repeatedly. I guess I could use a for loop but that's somewhat unweildly > on the command line. man xargs --keith -- kkeller-usenet@wombat.san-francisco.ca.us (try just my userid to email me) AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt see X- headers for PGP signature information |
|
|||
|
Rahul wrote:
> Sometimes I have commands that are designed only to process a single > input argument but I want to call them repeatedly on a list. > > For example I generate a command line pipe that outputs a list of ip > addresses: > > cmd1 | cmd2 | tr '\n' '\t' > > 11.0.0.21 11.0.0.176 11.0.0.191 > > To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex > <ip address> > > Is there a command line metaphor to feed a command one arg at a time > repeatedly. I guess I could use a for loop but that's somewhat unweildly > on the command line. > Assuming your "cmd1 | cmd2" pipe above outputs a single IP address per line, try: cmd1 | cmd2 | xargs --max-args=1 ip2hex Regards, Kees. -- Kees Theunissen |
|
|||
|
Kees Theunissen <theuniss@rijnh.nl> wrote in
news:481a2703$0$14343$e4fe514c@news.xs4all.nl: > Assuming your "cmd1 | cmd2" pipe above outputs a single IP address > per line, try: > > cmd1 | cmd2 | xargs --max-args=1 ip2hex Thanks Kees and Keith. That's perfect. I had tried xargs before I posted but did not realize the --max-args option was what I needed! -- Rahul |
|
|||
|
Rahul wrote:
> Sometimes I have commands that are designed only to process a single > input argument but I want to call them repeatedly on a list. > > For example I generate a command line pipe that outputs a list of ip > addresses: > > cmd1 | cmd2 | tr '\n' '\t' > > 11.0.0.21 11.0.0.176 11.0.0.191 > > To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex > <ip address> > > Is there a command line metaphor to feed a command one arg at a time > repeatedly. I guess I could use a for loop but that's somewhat unweildly > on the command line. > xargs -n 1 See 'man xargs' for details. Janis |
|
|||
|
On 2008-05-01, Rahul <nospam@nospam.invalid> wrote:
> Sometimes I have commands that are designed only to process a single > input argument but I want to call them repeatedly on a list. > > For example I generate a command line pipe that outputs a list of ip > addresses: > > cmd1 | cmd2 | tr '\n' '\t' > > 11.0.0.21 11.0.0.176 11.0.0.191 > > To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex ><ip address> > > Is there a command line metaphor to feed a command one arg at a time > repeatedly. I guess I could use a for loop but that's somewhat unweildly > on the command line. > xargs has the -n flag to control how many arguments it uses at a time; it spawns as many instances of the program as necessary to use up all the arguments: other_stuff | xargs -n 1 ip2hex -- Christopher Mattern NOTICE Thank you for noticing this new notice Your noticing it has been noted And will be reported to the authorities |
|
|||
|
On 2008-05-01, Rahul <nospam@nospam.invalid> wrote:
> > > Sometimes I have commands that are designed only to process a single > input argument but I want to call them repeatedly on a list. > > For example I generate a command line pipe that outputs a list of ip > addresses: > > cmd1 | cmd2 | tr '\n' '\t' > > 11.0.0.21 11.0.0.176 11.0.0.191 > > To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex ><ip address> > > Is there a command line metaphor to feed a command one arg at a time > repeatedly. I guess I could use a for loop but that's somewhat unweildly > on the command line. > while read ip_address |
|
|||
|
On Thu, 01 May 2008 20:06:21 +0000, Rahul wrote:
> Sometimes I have commands that are designed only to process a single > input argument but I want to call them repeatedly on a list. > > For example I generate a command line pipe that outputs a list of ip > addresses: > > cmd1 | cmd2 | tr '\n' '\t' > > 11.0.0.21 11.0.0.176 11.0.0.191 > > To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex > <ip address> > > Is there a command line metaphor to feed a command one arg at a time > repeatedly. I guess I could use a for loop but that's somewhat unweildly > on the command line. cmd1 | cmd2 | while read ip ; do ip2hex $ip ; done does not look too bad to me. |
|
|||
|
On May 1, 4:06*pm, Rahul <nos...@nospam.invalid> wrote:
> Sometimes I have commands that are designed only to process a single > input argument but I want to call them repeatedly on a list. > > For example I generate a command line pipe that outputs a list of ip > addresses: > > cmd1 | cmd2 | tr '\n' '\t' > > 11.0.0.21 * * * 11.0.0.176 * * *11.0.0.191 > > To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex > <ip address> > > Is there a command line metaphor to feed a command one arg at a time > repeatedly. I guess I could use a for loop but that's somewhat unweildly > on the command line. > > -- > Rahul pipe your output thru xargs... cmd1 | cmd2 | tr '\n' '\t' | xargs -l ip2hex |
|
|||
|
On May 1, 4:06 pm, Rahul <nos...@nospam.invalid> wrote:
> Sometimes I have commands that are designed only to process a single > input argument but I want to call them repeatedly on a list. > > For example I generate a command line pipe that outputs a list of ip > addresses: > > cmd1 | cmd2 | tr '\n' '\t' > > 11.0.0.21 11.0.0.176 11.0.0.191 > > To convert to hex I have ip2hex that accepts only 1 arg. ip2hex: ip2hex > <ip address> > > Is there a command line metaphor to feed a command one arg at a time > repeatedly. I guess I could use a for loop but that's somewhat unweildly > on the command line. > > -- > Rahul You can use xargs -n1, which limits only one arg at a time. IIRC, this is GNU xargs and other versions may not support it. Check it out. Sashi |
![]() |
| Thread Tools | |
| Display Modes | |
|
|