Removing days
am 23.12.2007 13:21:56 von apogeusistemas
Hi:
I need remove all days from $a variable finded in $b variable, and I
create
this script, but I=B4m having errors...
a=3D"2 3 9 10 16 17 23 24 30 31"
b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 29 30 31"
for day in `echo $a`
do
c=3D`echo $b | tr -d $day`
done
echo $c
/script
2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
What could I modify to get this script working good ?
Thank You.
Re: Removing days
am 23.12.2007 14:07:12 von Cyrus Kriticos
apogeusistemas@gmail.com wrote:
> I need remove all days from $a variable finded in $b variable, and I
> create
> this script, but I´m having errors...
>
> a="2 3 9 10 16 17 23 24 30 31"
> b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> 26 27 28 29 30 31"
> for day in `echo $a`
> do
> c=`echo $b | tr -d $day`
> done
> echo $c
>
> ./script
>
> 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>
> What could I modify to get this script working good ?
c=$(echo $a $b | tr " " "\n" | sort -n | sort -u | tr "\n" " ")
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Re: Removing days
am 23.12.2007 14:11:38 von Cyrus Kriticos
apogeusistemas@gmail.com wrote:
> I need remove all days from $a variable finded in $b variable, and I
> create
> this script, but I´m having errors...
>
> a="2 3 9 10 16 17 23 24 30 31"
> b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> 26 27 28 29 30 31"
> for day in `echo $a`
> do
> c=`echo $b | tr -d $day`
> done
> echo $c
>
> ./script
>
> 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>
> What could I modify to get this script working good ?
c=$(echo $a $b | tr " " "\n" | sort -n | uniq -u | tr "\n" " ")
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Re: Removing days
am 23.12.2007 14:13:04 von apogeusistemas
On 23 dez, 11:11, Cyrus Kriticos
wrote:
> apogeusiste...@gmail.com wrote:
> > I need remove all days from $a variable finded in $b variable, and I
> > create
> > this script, but I=B4m having errors...
>
> > a=3D"2 3 9 10 16 17 23 24 30 31"
> > b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> > 26 27 28 29 30 31"
> > for day in `echo $a`
> > do
> > =A0 c=3D`echo $b | tr -d $day`
> > done
> > echo $c
>
> > ./script
>
> > 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>
> > What could I modify to get this script working good ?
>
> c=3D$(echo $a $b | tr " " "\n" | sort -n | uniq -u | tr "\n" " ")
>
> --
> =A0 =A0Best regards =A0| =A0Be nice to America or they'll bring democracy =
to
> =A0 =A0Cyrus =A0 =A0 =A0 =A0 | =A0your country.- Ocultar texto entre aspas=
-
>
> - Mostrar texto entre aspas -
I got this output:
1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30
31 4 5 6 7 8 9
Re: Removing days
am 23.12.2007 14:18:08 von apogeusistemas
On 23 dez, 11:11, Cyrus Kriticos
wrote:
> apogeusiste...@gmail.com wrote:
> > I need remove all days from $a variable finded in $b variable, and I
> > create
> > this script, but I=B4m having errors...
>
> > a=3D"2 3 9 10 16 17 23 24 30 31"
> > b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> > 26 27 28 29 30 31"
> > for day in `echo $a`
> > do
> > =A0 c=3D`echo $b | tr -d $day`
> > done
> > echo $c
>
> > ./script
>
> > 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>
> > What could I modify to get this script working good ?
>
> c=3D$(echo $a $b | tr " " "\n" | sort -n | uniq -u | tr "\n" " ")
>
> --
> =A0 =A0Best regards =A0| =A0Be nice to America or they'll bring democracy =
to
> =A0 =A0Cyrus =A0 =A0 =A0 =A0 | =A0your country.- Ocultar texto entre aspas=
-
>
> - Mostrar texto entre aspas -
Thanks again, Cyrus !
Re: Removing days
am 23.12.2007 14:19:26 von Cyrus Kriticos
apogeusistemas@gmail.com wrote:
> On 23 dez, 11:11, Cyrus Kriticos
> wrote:
>> apogeusiste...@gmail.com wrote:
>>> I need remove all days from $a variable finded in $b variable, and I
>>> create
>>> this script, but I´m having errors...
>>> a="2 3 9 10 16 17 23 24 30 31"
>>> b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
>>> 26 27 28 29 30 31"
>>> for day in `echo $a`
>>> do
>>> c=`echo $b | tr -d $day`
>>> done
>>> echo $c
>>> ./script
>>> 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>>> What could I modify to get this script working good ?
>> c=$(echo $a $b | tr " " "\n" | sort -n | uniq -u | tr "\n" " ")
>>
>> --
>> Best regards | Be nice to America or they'll bring democracy to
>> Cyrus | your country.- Ocultar texto entre aspas -
>>
>> - Mostrar texto entre aspas -
>
> I got this output:
>
> 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30
> 31 4 5 6 7 8 9
I got this:
$ a="2 3 9 10 16 17 23 24 30 31"
$ b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31"
$ c=$(echo $a $b | tr " " "\n" | sort -n | uniq -u | tr "\n" " ")
$ echo $c
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
and
$ for i in tr sort uniq head bash; do $i --version | head -n 1 ; done
tr (GNU coreutils) 5.97
sort (GNU coreutils) 5.97
uniq (GNU coreutils) 5.97
head (GNU coreutils) 5.97
GNU bash, version 3.2.13(1)-release (i486-pc-linux-gnu)
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Re: Removing days
am 23.12.2007 16:23:11 von PK
apogeusistemas@gmail.com wrote:
> Hi:
> I need remove all days from $a variable finded in $b variable, and I
> create
> this script, but I´m having errors...
>
> a="2 3 9 10 16 17 23 24 30 31"
> b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> 26 27 28 29 30 31"
> for day in `echo $a`
> do
> c=`echo $b | tr -d $day`
> done
> echo $c
>
> ./script
>
> 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>
> What could I modify to get this script working good ?
For example:
a="2 3 9 10 16 17 23 24 30 31"
b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 \
28 29 30 31"
for day in $a; do
b=`echo "$b" | sed -e "s/\([ ^]\)$day\([ $]\)/\1\2/g"`
done
echo "$b" | tr -s ' '
Re: Removing days
am 23.12.2007 16:36:02 von Ed Morton
On 12/23/2007 6:21 AM, apogeusistemas@gmail.com wrote:
> Hi:
> I need remove all days from $a variable finded in $b variable, and I
> create
> this script, but I=B4m having errors...
>=20
> a=3D"2 3 9 10 16 17 23 24 30 31"
> b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> 26 27 28 29 30 31"
> for day in `echo $a`
> do
> c=3D`echo $b | tr -d $day`
> done
> echo $c
>=20
> ./script
>=20
> 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>=20
> What could I modify to get this script working good ?
>=20
> Thank You.
Your script seems to be trying to do the opposite of what you say, so I'm=
not
sure what you really want, but maybe this will give you an idea:
$ a=3D"2 3 9 10 16 17 23 24 30 31"
$ b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 =
26 27
29 30 31"
$ A=3D`echo "$a" | tr ' ' '\n'`
$ B=3D`echo "$b" | tr ' ' '\n'`
$ C=3D`comm -13 <(echo "$A") <(echo "$B")`
$ c=3D`echo $C`
$ echo "$c"
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
man comm for details.
Regards,
Ed.
Re: Removing days
am 23.12.2007 17:50:26 von Janis Papanagnou
Ed Morton wrote:
>
> On 12/23/2007 6:21 AM, apogeusistemas@gmail.com wrote:
>
>>Hi:
>>I need remove all days from $a variable finded in $b variable, and I
>>create
>>this script, but I´m having errors...
>>
>>a="2 3 9 10 16 17 23 24 30 31"
>>b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
>>26 27 28 29 30 31"
>>for day in `echo $a`
>>do
>> c=`echo $b | tr -d $day`
>>done
>>echo $c
>>
>>./script
>>
>>2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>>
>>What could I modify to get this script working good ?
>>
>>Thank You.
>
>
> Your script seems to be trying to do the opposite of what you say, so I'm not
> sure what you really want, but maybe this will give you an idea:
>
> $ a="2 3 9 10 16 17 23 24 30 31"
> $ b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
> 29 30 31"
> $ A=`echo "$a" | tr ' ' '\n'`
> $ B=`echo "$b" | tr ' ' '\n'`
> $ C=`comm -13 <(echo "$A") <(echo "$B")`
One could move the tr pipes into the process substitution brackets.
Or - since we use shells that already support process substitution -
even use parameter expansion instead of tr; e.g. in ksh93 or bash3...
C=$( comm -13 <(echo "${a// /$'\n'}") <(echo "${b// /$'\n'}") )
Janis
> $ c=`echo $C`
> $ echo "$c"
> 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
>
> man comm for details.
>
> Regards,
>
> Ed.
>
Re: Removing days
am 23.12.2007 19:17:33 von Ed Morton
On 12/23/2007 10:50 AM, Janis Papanagnou wrote:
> Ed Morton wrote:
>=20
>>On 12/23/2007 6:21 AM, apogeusistemas@gmail.com wrote:
>>
>>
>>>Hi:
>>>I need remove all days from $a variable finded in $b variable, and I
>>>create
>>>this script, but I=B4m having errors...
>>>
>>>a=3D"2 3 9 10 16 17 23 24 30 31"
>>>b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25=
>>>26 27 28 29 30 31"
>>>for day in `echo $a`
>>>do
>>> c=3D`echo $b | tr -d $day`
>>>done
>>>echo $c
>>>
>>>./script
>>>
>>>2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>>>
>>>What could I modify to get this script working good ?
>>>
>>>Thank You.
>>
>>
>>Your script seems to be trying to do the opposite of what you say, so I=
'm not
>>sure what you really want, but maybe this will give you an idea:
>>
>>$ a=3D"2 3 9 10 16 17 23 24 30 31"
>>$ b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2=
5 26 27
>> 29 30 31"
>>$ A=3D`echo "$a" | tr ' ' '\n'`
>>$ B=3D`echo "$b" | tr ' ' '\n'`
>>$ C=3D`comm -13 <(echo "$A") <(echo "$B")`
>=20
>=20
> One could move the tr pipes into the process substitution brackets.
Yeah, I know it could be reduced to:
$ a=3D"2 3 9 10 16 17 23 24 30 31"
$ b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 =
26 27 29
30 31"
$ c=3D`comm -13 <(echo "$A" |tr ' ' '\n') <(echo "$B" |tr ' ' '\n') |tr '=
\n' ' '`
$ echo "$c"
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 29
but I was shooting for clarity....
> Or - since we use shells that already support process substitution -
> even use parameter expansion instead of tr; e.g. in ksh93 or bash3...
>=20
> C=3D$( comm -13 <(echo "${a// /$'\n'}") <(echo "${b// /$'\n'}") )
True. Much prettier.
Ed.
>=20
> Janis
>=20
>=20
>>$ c=3D`echo $C`
>>$ echo "$c"
>>1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
>>
>>man comm for details.
>>
>>Regards,
>>
>> Ed.
>>
>=20
Re: Removing days
am 23.12.2007 19:19:21 von Ed Morton
On 12/23/2007 12:17 PM, Ed Morton wrote:
Correction:
> Yeah, I know it could be reduced to:
>
> $ a="2 3 9 10 16 17 23 24 30 31"
> $ b="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29
> 30 31"
> $ c=`comm -13 <(echo "$A" |tr ' ' '\n') <(echo "$B" |tr ' ' '\n') |tr '\n' ' '`
$ c=`comm -13 <(echo "$a" |tr ' ' '\n') <(echo "$b" |tr ' ' '\n') |tr '\n' ' '`
> $ echo "$c"
> 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 29
Ed.
Re: Removing days
am 24.12.2007 06:08:48 von William James
On Dec 23, 7:19 am, Cyrus Kriticos
wrote:
> apogeusiste...@gmail.com wrote:
> > On 23 dez, 11:11, Cyrus Kriticos
> > wrote:
> >> apogeusiste...@gmail.com wrote:
> >>> I need remove all days from $a variable finded in $b variable, and I
> >>> create
> >>> this script, but I=B4m having errors...
> >>> a=3D"2 3 9 10 16 17 23 24 30 31"
> >>> b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25=
> >>> 26 27 28 29 30 31"
> >>> for day in `echo $a`
> >>> do
> >>> c=3D`echo $b | tr -d $day`
> >>> done
> >>> echo $c
> >>> ./script
> >>> 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
> >>> What could I modify to get this script working good ?
> >> c=3D$(echo $a $b | tr " " "\n" | sort -n | uniq -u | tr "\n" " ")
>
> >> --
> >> Best regards | Be nice to America or they'll bring democracy to
> >> Cyrus | your country.- Ocultar texto entre aspas -
>
> >> - Mostrar texto entre aspas -
>
> > I got this output:
>
> > 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30
> > 31 4 5 6 7 8 9
>
> I got this:
>
> $ a=3D"2 3 9 10 16 17 23 24 30 31"
> $ b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 2=
6
> 27 28 29 30 31"
> $ c=3D$(echo $a $b | tr " " "\n" | sort -n | uniq -u | tr "\n" " ")
> $ echo $c
> 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
>
> and
>
> $ for i in tr sort uniq head bash; do $i --version | head -n 1 ; done
> tr (GNU coreutils) 5.97
> sort (GNU coreutils) 5.97
> uniq (GNU coreutils) 5.97
> head (GNU coreutils) 5.97
> GNU bash, version 3.2.13(1)-release (i486-pc-linux-gnu)
Ruby:
a =3D "2 3 9 10 16 17 23 24 30 31"
b =3D "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
22 23 24 25 26 27 28 29 30 31"
puts (b.split - a.split).join(" ")
---- output ----
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
Re: Removing days
am 24.12.2007 11:10:15 von Rakesh Sharma
You need to re-word your requirements. What you need is to delete the
days from the $b variable not found in the $a variable.
What you wrote is days in $a not to be found in $b, which are none,
since every element of $a variable is present in $b.
### strip any newlines in the $a variable & pad with spaces.
aa=3D" `echo $a` "; # Note: $a variable deliberately left unquoted.
bNOTa=3D
for day in $b; do
case $aa in
*\ "$day"\ * ) :;;
*) bNOTa=3D${bNOTa}${bNOTa:+' '}${day};;
esac
done
echo "\$bNOTa=3D|$bNOTa|"
###############################################
On Dec 23, 5:21 pm, apogeusiste...@gmail.com wrote:
> Hi:
> I need remove all days from $a variable finded in $b variable, and I
> create
> this script, but I=B4m having errors...
>
> a=3D"2 3 9 10 16 17 23 24 30 31"
> b=3D"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> 26 27 28 29 30 31"
> for day in `echo $a`
> do
> c=3D`echo $b | tr -d $day`
> done
> echo $c
>
> ./script
>
> 2 4 5 6 7 8 9 0 2 4 5 6 7 8 9 20 2 22 2 24 25 26 27 28 29 0
>
> What could I modify to get this script working good ?
>
> Thank You.
Re: Removing days
am 24.12.2007 11:11:12 von PK
William James wrote:
> Ruby:
>
> a = "2 3 9 10 16 17 23 24 30 31"
> b = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
> 22 23 24 25 26 27 28 29 30 31"
> puts (b.split - a.split).join(" ")
>
> ---- output ----
> 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
php:
$a = array(2,3,9,10,16,17,23,24,30,31);
$b = range(1,31);
$r = array_diff($a, $b);
Re: Removing days
am 24.12.2007 11:15:35 von Cyrus Kriticos
pk wrote:
> William James wrote:
>
>> Ruby:
>>
>> a = "2 3 9 10 16 17 23 24 30 31"
>> b = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
>> 22 23 24 25 26 27 28 29 30 31"
>> puts (b.split - a.split).join(" ")
>>
>> ---- output ----
>> 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
>
> php:
>
> $a = array(2,3,9,10,16,17,23,24,30,31);
> $b = range(1,31);
> $r = array_diff($a, $b);
Wie sieht der Output aus?
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Re: Removing days
am 24.12.2007 11:17:07 von Cyrus Kriticos
pk wrote:
> William James wrote:
>
>> Ruby:
>>
>> a = "2 3 9 10 16 17 23 24 30 31"
>> b = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
>> 22 23 24 25 26 27 28 29 30 31"
>> puts (b.split - a.split).join(" ")
>>
>> ---- output ----
>> 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
>
> php:
>
> $a = array(2,3,9,10,16,17,23,24,30,31);
> $b = range(1,31);
> $r = array_diff($a, $b);
And the output?
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Re: Removing days
am 24.12.2007 12:13:53 von PK
Cyrus Kriticos wrote:
>> php:
>>
>> $a = array(2,3,9,10,16,17,23,24,30,31);
>> $b = range(1,31);
>> $r = array_diff($a, $b);
>
> And the output?
Change the last line (for example) to:
printf("%s\n", implode(' ', array_diff($b, $a)));
or one of the other bazillions php string/array manipulation methods...
Re: Removing days
am 24.12.2007 18:08:33 von William James
On Dec 24, 4:11 am, pk
wrote:
> William James wrote:
> > Ruby:
>
> > a = "2 3 9 10 16 17 23 24 30 31"
> > b = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
> > 22 23 24 25 26 27 28 29 30 31"
> > puts (b.split - a.split).join(" ")
>
> > ---- output ----
> > 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
>
> php:
>
> $a = array(2,3,9,10,16,17,23,24,30,31);
> $b = range(1,31);
> $r = array_diff($a, $b);
You didn't show $a starting as a string, not
an array. What are those silly semicolons for?
Even awk doesn't need semicolons. And this
doesn't produce any output.
a = "2 3 9 10 16 17 23 24 30 31"
puts ( (1..31).to_a - a.split.map{|s| s.to_i} ).join(" ")
a = %w(2 3 9 10 16 17 23 24 30 31)
puts ( (1..31).to_a - a.map{|s| s.to_i} ).join(" ")
a = [2,3,9,10,16,17,23,24,30,31]
puts ( (1..31).to_a - a ).join(" ")
a = 2,3,9,10,16,17,23,24,30,31
puts ( (1..31).to_a - a ).join(' ')
a = 2,3,9,10,16,17,23,24,30,31
puts ( [*(1..31)] - a ).join(' ')
---- output ----
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
Re: Removing days
am 24.12.2007 18:14:08 von William James
On Dec 24, 11:08 am, William James wrote:
> On Dec 24, 4:11 am, pk wrote:
>
> > William James wrote:
> > > Ruby:
>
> > > a = "2 3 9 10 16 17 23 24 30 31"
> > > b = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
> > > 22 23 24 25 26 27 28 29 30 31"
> > > puts (b.split - a.split).join(" ")
>
> > > ---- output ----
> > > 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29
>
> > php:
>
> > $a = array(2,3,9,10,16,17,23,24,30,31);
> > $b = range(1,31);
> > $r = array_diff($a, $b);
>
> You didn't show $a starting as a string, not
> an array. What are those silly semicolons for?
> Even awk doesn't need semicolons. And this
> doesn't produce any output.
>
> a = "2 3 9 10 16 17 23 24 30 31"
> puts ( (1..31).to_a - a.split.map{|s| s.to_i} ).join(" ")
>
> a = %w(2 3 9 10 16 17 23 24 30 31)
> puts ( (1..31).to_a - a.map{|s| s.to_i} ).join(" ")
>
> a = [2,3,9,10,16,17,23,24,30,31]
> puts ( (1..31).to_a - a ).join(" ")
>
> a = 2,3,9,10,16,17,23,24,30,31
> puts ( (1..31).to_a - a ).join(' ')
>
> a = 2,3,9,10,16,17,23,24,30,31
> puts ( [*(1..31)] - a ).join(' ')
Please pardon my prolixity.
a = 2,3,9,10,16,17,23,24,30,31
puts ( [*1..31] - a ).join(' ')
Re: Removing days
am 24.12.2007 19:30:19 von PK
William James wrote:
> You didn't show $a starting as a string, not
> an array.
Not really difficult:
$a = explode(' ', "2 3 9 10 16 17 23 24 30 31");
> What are those silly semicolons for?
It's called "syntax". php statements must be terminated by semicolons.
> Even awk doesn't need semicolons.
Well, in case you don't know, perl, c and a great deal of other languages
do.
> And this doesn't produce any output.
See my other reply; the last line had to be different.
OT: synth axe was: Removing days
am 25.12.2007 12:07:01 von Loki Harfagr
On Mon, 24 Dec 2007 19:30:19 +0100, pk wrote:
> William James wrote:
>
>> You didn't show $a starting as a string, not an array.
>
> Not really difficult:
>
> $a = explode(' ', "2 3 9 10 16 17 23 24 30 31");
>
>> What are those silly semicolons for?
>
> It's called "syntax". php statements must be terminated by semicolons.
>
>> Even awk doesn't need semicolons.
>
> Well, in case you don't know, perl, c and a great deal of other
> languages do.
Isn't it supposed to be rude to put the words
'syntax' and 'Perl' in the same post ;D)
Happy new year! (and that's being proactive at removing days)