View Single Post

  #3 (permalink)  
Old 05-01-2008
Kees Theunissen
 
Posts: n/a
Default Re: feeding a series of input args to a command that only takes one

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
Reply With Quote