Hi Tiana

When you read in the file using READ/LINES each entry in the resultiing
block is a string. When you sort the block REBOL sorts the strings
lexicographically, so lines that that start with the character "2" will come
before lines that start with the character "6".  If you want them to sort by
date you could convert each line to a  block.

Like

>> file: read/lines %junk.txt
== ["2-Feb-2000  1   2" "1-Feb-2000  2   1" "6-Feb-2000  3   5" "24-Feb-2000
4
6"]
>> blk: make block! 10
== []
>> foreach line file [append/only blk to-block line]
== [[2-Feb-2000 1 2] [1-Feb-2000 2 1] [6-Feb-2000 3 5] [24-Feb-2000 4 6]]
>> sort blk
== [[1-Feb-2000 2 1] [2-Feb-2000 1 2] [6-Feb-2000 3 5] [24-Feb-2000 4 6]]
>>

Hope this helps

Larry


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, February 10, 2000 2:44 PM
Subject: [REBOL] problem with sort a file Re:(2)


> Hi, Mike
> Thanks for your reply.
>
> I use /skip because I thought it is for sectional sorting. in my file,
each
> record has 4 sections(e.g, 1-Feb-2000  bla bla bla). I just tried without
skip,
> it gave me the same result though. I guess this is might because of I read
it
> from a file?
>
> I use the following script and sample file,
>
> file: read/lines  %foo.txt
> blk: make block! 100
> blk: to-block file
> file2: sort blk
> write/lines  %foo2.txt file2
>
> which foo.txt is:
> 2-Feb-2000  1   2
> 1-Feb-2000  2   1
> 6-Feb-2000  3   5
> 24-Feb-2000 4   6
>
> the result foo2.txt is:
> 1-Feb-2000  2   1
> 2-Feb-2000  1   2
> 24-Feb-2000 4   6
> 6-Feb-2000  3   5
>
> It can't tell 24-Feb-2000 is larger than  6-Feb-2000. Why is it?

Reply via email to