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 > Command output as input for for/while look
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Command output as input for for/while look

Réponse
 
LinkBack Outils de la discussion
Vieux 17/07/2007, 10h38   #1
Martin Krischik
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Command output as input for for/while look

Hello,

I got two problems:

1) I once saw some nifty tricks on how to use the output from one
command as input for a for/while loop (looping over each line
outputted). But I can't just find it any more. :-(

2) While trying to make it up myself I noticed something nasty: The
output is from a secure shell connection to a machine which uses CR/LF
as line terminator - something Z-Shell did not like all that much. Any
ideas on what to to with unneeded CR's?

Martin
--
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com
  Réponse avec citation
Vieux 17/07/2007, 11h02   #2
Janis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Command output as input for for/while look

On 17 Jul., 11:38, Martin Krischik <krisc...@users.sourceforge.net>
wrote:
> Hello,
>
> I got two problems:
>
> 1) I once saw some nifty tricks on how to use the output from one
> command as input for a for/while loop (looping over each line
> outputted). But I can't just find it any more. :-(


your_command | while read -r field1 field2 rest ; do : anything ; done

The number of variables to read is just an example, you may just
want a single variable.

> 2) While trying to make it up myself I noticed something nasty: The
> output is from a secure shell connection to a machine which uses CR/LF
> as line terminator - something Z-Shell did not like all that much. Any
> ideas on what to to with unneeded CR's?


Remove them from your data stream if you don't want them

your_command | tr -d '\015'

tr -d '\015' <your_data_file


Janis

> Martin
> --
> mailto://krisc...@users.sourceforge.net
> Ada programming at:http://ada.krischik.com



  Réponse avec citation
Vieux 18/07/2007, 23h01   #3
johngnub
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Command output as input for for/while look

On Jul 17, 3:02 am, Janis <janis_papanag...@hotmail.com> wrote:
> On 17 Jul., 11:38, Martin Krischik <krisc...@users.sourceforge.net>
> wrote:
>
> > Hello,

>
> > I got two problems:

>
> > 1) I once saw some nifty tricks on how to use the output from one
> > command as input for a for/while loop (looping over each line
> > outputted). But I can't just find it any more. :-(

>
> your_command | while read -r field1 field2 rest ; do : anything ; done
>
> The number of variables to read is just an example, you may just
> want a single variable.
>
> > 2) While trying to make it up myself I noticed something nasty: The
> > output is from a secure shell connection to a machine which uses CR/LF
> > as line terminator - something Z-Shell did not like all that much. Any
> > ideas on what to to with unneeded CR's?

>
> Remove them from your data stream if you don't want them
>
> your_command | tr -d '\015'
>
> tr -d '\015' <your_data_file
>
> Janis
>
> > Martin
> > --
> > mailto://krisc...@users.sourceforge.net
> > Ada programming at:http://ada.krischik.com


One trick I have used in the past, not sure if it can work for you in
this example, But
I have used tee -a mylog.log ( append ) in the loop to get each loop
to write to the same file, eg:
for x in *
do
echo "File $x" |tee -a list.log
done

DANGER, this can make a big file if you run the same command using the
same file name for tee, option, use "$$.log" to make new file, just a
thought.

2 cents JB

  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 05h18.


É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,11229 seconds with 11 queries