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 > Who to direct output of one command as a argument of next command
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Who to direct output of one command as a argument of next command

Réponse
 
LinkBack Outils de la discussion
Vieux 03/09/2007, 14h19   #1
JoshforRefugee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Who to direct output of one command as a argument of next command

I need to direct output of one command as a argument of next command,
but don't know how to do it on command line

for example
ls -rt | grep sv | tail -1 ---> will give me last modified file. I
like to cat on this file.

ls -rl | grep sv | tail -1 | cat --> will not do what I am trying to
do.

  Réponse avec citation
Vieux 03/09/2007, 14h47   #2
Jeroen van Nieuwenhuizen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Who to direct output of one command as a argument of next command

On Mon, 03 Sep 2007 06:19:13 -0700
somebody claiming to be JoshforRefugee wrote:
> I need to direct output of one command as a argument of next command,
> but don't know how to do it on command line
>
> for example
> ls -rt | grep sv | tail -1 ---> will give me last modified file. I
> like to cat on this file.
>
> ls -rl | grep sv | tail -1 | cat --> will not do what I am trying to
> do.


cat `ls -rl | grep sv | tail -1`

Kind regards,

Jeroen.

--
ir. Jeroen van Nieuwenhuizen
Email: jnieuwen [at] jeroen [dot] se
I know I'm not perfect but I can smile
  Réponse avec citation
Vieux 03/09/2007, 14h47   #3
Jeroen van Nieuwenhuizen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Who to direct output of one command as a argument of next command

On Mon, 03 Sep 2007 06:19:13 -0700
somebody claiming to be JoshforRefugee wrote:
> I need to direct output of one command as a argument of next command,
> but don't know how to do it on command line
>
> for example
> ls -rt | grep sv | tail -1 ---> will give me last modified file. I
> like to cat on this file.
>
> ls -rl | grep sv | tail -1 | cat --> will not do what I am trying to
> do.


cat `ls -rl | grep sv | tail -1`

Kind regards,

Jeroen.

--
ir. Jeroen van Nieuwenhuizen
Email: jnieuwen [at] jeroen [dot] se
I know I'm not perfect but I can smile
  Réponse avec citation
Vieux 03/09/2007, 15h31   #4
arch119
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Who to direct output of one command as a argument of next command

On Sep 3, 10:19 pm, JoshforRefugee <anki...@yahoo.com> wrote:
> I need to direct output of one command as a argument of next command,
> but don't know how to do it on command line


Try using xargs but be careful about spaces in the output of command
1.

> for example
> ls -rt | grep sv | tail -1 ---> will give me last modified file. I
> like to cat on this file.


Provided your file names don't have any space within,
ls -rt | grep sv | tail -1 | xargs cat


  Réponse avec citation
Vieux 04/09/2007, 11h29   #5
JoshforRefugee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Who to direct output of one command as a argument of next command

Thanks Jeroen and Arch119.
One more general question.

How can I eliminate additional spaces or is there search and replace I
can do on xargs.

ls -rt | grep old | tail -1 | s/old/new/ | xargs touch.

So in this case, I am grabbing oldest file with *old* name, and
creating new file (with replacing old from discovered file name with
new)

  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 07h23.


É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,09896 seconds with 13 queries