Compare list of values.
am 09.09.2007 23:02:45 von 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).
Tanks a lot.
Re: Compare list of values.
am 09.09.2007 23:30:57 von Stephane CHAZELAS
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
Re: Compare list of values.
am 09.09.2007 23:33:52 von cichomitiko
"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
Re: Compare list of values.
am 09.09.2007 23:42:24 von Stephane CHAZELAS
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
Re: Compare list of values.
am 09.09.2007 23:51:17 von cichomitiko
"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
Re: Compare list of values.
am 10.09.2007 00:12:42 von slystoner
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
....
Re: Compare list of values.
am 10.09.2007 01:06:35 von William James
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'
Re: Compare list of values.
am 10.09.2007 10:03:16 von jazy333
On Sep 10, 7:06 am, William James 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'
:)