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 > Compare list of values.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Compare list of values.

Réponse
 
LinkBack Outils de la discussion
Vieux 09/09/2007, 22h02   #1
slystoner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Compare list of values.

The output of a script is somethinh like:

$./foo.sh
123
123
123
123
123
123
123
123
123


I have to rename the directory when I run that script if all the values
in output are the same, but.. how can I compare all that values? (I
don't know how much values I will get).

Tanks a lot.
  Réponse avec citation
Vieux 09/09/2007, 22h30   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compare list of values.

2007-09-09, 23:02(+02), slystoner:
> The output of a script is somethinh like:
>
> $./foo.sh
> 123
> 123
> 123
> 123
> 123
> 123
> 123
> 123
> 123
>
>
> I have to rename the directory when I run that script if all the values
> in output are the same, but.. how can I compare all that values? (I
> don't know how much values I will get).

[...]

if ./foo.sh |
awk 'NR > 1 && $0 != last {exit 1} {last = $0}'
then
echo "all the lines output by ./foo.sh were identical"
else
echo "they were not"
fi

--
Stéphane
  Réponse avec citation
Vieux 09/09/2007, 22h33   #3
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compare list of values.


"slystoner" wrote ...
> The output of a script is somethinh like:
>
> $./foo.sh
> 123
> 123
> 123
> 123
> 123
> 123
> 123
> 123
> 123
>
>
> I have to rename the directory when I run that script if all the values in
> output are the same

[...]

With zsh:

[[ $(print ${(u)$(foo.sh)}) = 123 ]]&&mv ...


Dimitre


  Réponse avec citation
Vieux 09/09/2007, 22h42   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compare list of values.

2007-09-9, 23:33(+02), Radoulov, Dimitre:
[...]
> With zsh:
>
> [[ $(print ${(u)$(foo.sh)}) = 123 ]]&&mv ...

[...]

Except that if the output contains empty lines (and if that's a
problem), they will not be noticed. And note that print
'\006123' also outputs "123" (followed by a LF).

--
Stéphane
  Réponse avec citation
Vieux 09/09/2007, 22h51   #5
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compare list of values.


"Stephane CHAZELAS" wrote ...
> 2007-09-9, 23:33(+02), Radoulov, Dimitre:
> [...]
>> With zsh:
>>
>> [[ $(print ${(u)$(foo.sh)}) = 123 ]]&&mv ...

> [...]
>
> Except that if the output contains empty lines (and if that's a
> problem), they will not be noticed. And note that print
> '\006123' also outputs "123" (followed by a LF).


Thanks for pointing that.

So if the value is unknown and the above mentioned is not a problem:

[ ${#${(u)$(foo.sh)}} -eq 1 ]&&mv ...


Dimitre


  Réponse avec citation
Vieux 09/09/2007, 23h12   #6
slystoner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compare list of values.

Stephane CHAZELAS ha scritto:
> if ./foo.sh |
> awk 'NR > 1 && $0 != last {exit 1} {last = $0}'
> then
> echo "all the lines output by ./foo.sh were identical"
> else
> echo "they were not"
> fi
>

I found a solution but.. your's so compact!
Damn.. Stephane rocks!



function checkDIR() {
FOO=`./script,sh' | tail -1`

for ITEM in `./script.sh`;
do
if [$FOO -eq $ITEM]
then
return 0
fi
done
return 1
}

if checkDIR;
do
....

  Réponse avec citation
Vieux 10/09/2007, 00h06   #7
William James
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compare list of values.


Stephane CHAZELAS wrote:
> 2007-09-09, 23:02(+02), slystoner:
> > The output of a script is somethinh like:
> >
> > $./foo.sh
> > 123
> > 123
> > 123
> > 123
> > 123
> > 123
> > 123
> > 123
> > 123
> >
> >
> > I have to rename the directory when I run that script if all the values
> > in output are the same, but.. how can I compare all that values? (I
> > don't know how much values I will get).

> [...]
>
> if ./foo.sh |
> awk 'NR > 1 && $0 != last {exit 1} {last = $0}'
> then
> echo "all the lines output by ./foo.sh were identical"
> else
> echo "they were not"
> fi


ruby -e 'exit 1 if ARGF.to_a.uniq.size>1'

  Réponse avec citation
Vieux 10/09/2007, 09h03   #8
jazy333@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compare list of values.

On Sep 10, 7:06 am, William James <w_a_x_...@yahoo.com> wrote:
> Stephane CHAZELAS wrote:
> > 2007-09-09, 23:02(+02), slystoner:
> > > The output of a script is somethinh like:

>
> > > $./foo.sh
> > > 123
> > > 123
> > > 123
> > > 123
> > > 123
> > > 123
> > > 123
> > > 123
> > > 123

>
> > > I have to rename the directory when I run that script if all the values
> > > in output are the same, but.. how can I compare all that values? (I
> > > don't know how much values I will get).

> > [...]

>
> > if ./foo.sh |
> > awk 'NR > 1 && $0 != last {exit 1} {last = $0}'
> > then
> > echo "all the lines output by ./foo.sh were identical"
> > else
> > echo "they were not"
> > fi

>
> ruby -e 'exit 1 if ARGF.to_a.uniq.size>1'




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


É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,18387 seconds with 16 queries