Mike,
I agree with your opinion, but when I tried your script, it gave me the
following msg:
** Script Error: Out of range or past end.
** Where: to-date first parse a none

Any idea? OR is that the problem of my foo1.txt?

Thanks a lot.

Tiana

____________________Reply Separator____________________
Subject:    [REBOL] problem with sort a file Re:(3) 
Author: <[EMAIL PROTECTED]>
Date:       2/10/00 3:20 PM

"Sectional sorting" goes over my head. Your file is being sorted according
to the ascii values. I.e. you haven't told it to sort according to a DATE.
Try this:

file-blk: read/lines %foo1.txt
sort/compare file-blk func[a b][(to-date first parse a none) > (to-date
first parse b none)]
write/lines %foo2.txt file-blk

Explanation:
> When you read in a file with read/lines, the result is a block of the
lines (strings) of the file.
> Sort modifies the contents of the block given to it.
> PARSE <block> NONE breaks apart the fields of the string into a series
(according to whitespace)
> FIRST takes the first field - in this case a string!
> TO-DATE converts the string to the internal date format, which will be
compared as expected
> I found that parenthesis are required here

- Michael Jelinek
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 10, 2000 2:45 PM
To: [EMAIL PROTECTED]
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  %foo1.txt
blk: make block! 100
blk: to-block file
file2: sort blk 
write/lines  %foo2.txt file2

which foo1.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