Hello [EMAIL PROTECTED],
Below is a modified version of Andrew's script
It uses a function for comparison (sort command has a /compare refinement)
the strings in the loaded block is never modified, so context is preserved.
Original formatting of file is *almost* preserved, except:
* if original file has no line-feed at the end, the output file will have
* all lines must be loadable by rebol, ie. {2-Feb-2000 @@ 2} won't go,
because @@ can't be loaded.
Furthermore there'll be a speed penalty over Andrew's version, as the lines
will have to be loaded each time.
let's go:
my-compare: func [a b] [
(load a) < (load b)
]
write %foo.txt
{2-Feb-2000 1 2
1-Feb-2000 2 1
6-Feb-2000 3 5
24-Feb-2000 4 6}
lines: read/lines %foo.txt
print mold lines
sort/compare lines :my-compare
print mold lines
write/lines %foo-sorted.txt lines
print read %foo-sorted.txt
Best regards
Thomas Jensen
On 11-Feb-00, [EMAIL PROTECTED] wrote:
> Hi, Andrew,
>
> Thanks for your script. It worked fine except one problem:
> It won't preserve the original format of the file. e.g
> 30-Jan-2000 4 6 (before sort)
> 30-Jan-2000 4 6 (after sort)
>
> Any suggestion about how to fix it?
>
> Thanks a lot.
>
> Tiana
>
> ____________________Reply Separator____________________
> Subject: [REBOL] problem with sort a file Re:(3)
> Author: <[EMAIL PROTECTED]>
> Date: 2/10/00 11:20 PM
>
> Try this:
>
> write %foo.txt
> {2-Feb-2000 1 2
> 1-Feb-2000 2 1
> 6-Feb-2000 3 5
> 24-Feb-2000 4 6}
>
> Lines: read/lines %foo.txt
> Block: make block! 100
> foreach Line Lines [
> append/only Block load Line
> ]
>
> print mold Block
> sort Block
> print mold Block
>
> delete %foo.txt
>
> foreach Line Block [
> write/append %foo.txt rejoin ["" line newline]
> ]
>
> print read %foo.txt
>
> Andrew Martin
> REBOLutionary in NZ...
> ICQ: 26227169
> http://members.xoom.com/AndrewMartin/
> -><-
>
>
>
>