From Newsgroup: comp.lang.lisp
(defun sort-file-lines (input-file output-file)
(with-open-file (instream input-file :direction :input)
(with-open-file (outstream output-file :direction :output)
(dolist (line (sort (loop for line = (read-line instream nil nil)
while line
collect line)
#'string-lessp))
(write-line line outstream)))))
Gauche Scheme:
(use file.util)
(define (sort-file-lines in-file out-file)
(with-output-to-file out-file
(lambda ()
(for-each print (sort (file->string-list in-file))))))
(sort-file-lines "data.bak" "junk")
--- Synchronet 3.21d-Linux NewsLink 1.2