PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > feeding a series of input args to a command that only takes one
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

feeding a series of input args to a command that only takes one

Réponse
 
LinkBack Outils de la discussion
Vieux 01/05/2008, 21h06   #1
Rahul
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut feeding a series of input args to a command that only takes one

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
  Réponse avec citation
Vieux 02/05/2008, 15h56   #2
James Michael Fultz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: feeding a series of input args to a command that only takes one

* Rahul <nospam@nospam.invalid>:
> 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

For example:

cmd1 | cmd2 | xargs -n1 ip2hex

--
James Michael Fultz <xyzzy@sent.as.invalid>
Remove this part when replying ^^^^^^^^
  Réponse avec citation
Vieux 02/05/2008, 23h19   #3
gypsy3001@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: feeding a series of input args to a command that only takes one

> xargs
> For example:
> cmd1 | cmd2 | xargs -n1 ip2hex


Looks like I re-wrote a simpler version of xargs a month ago . . .
learn something new everyday. Thanks for pointing out xargs.

Chieh
--
http://www.cynosurex.com/
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h46.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10739 seconds with 11 queries