[Create a new console application. In some versions of Delphi, you will need
to create a normal application, strip all forms, and add {$APPTYPE CONSOLE} in
the project source under "program"]
uses
SysUtils,classes; {add classes to the used units to get TStringlist}
var {variable declaration}
fil:TStringlist; {a list of strings for the file}
n:integer; {a whole number variable to step through the lines}
begin {begin of main block}
fil:=TStringlist.create; {create the string list object}
fil.loadfromfile(paramstr(1)); {load the textfile specified as first parameter into the list}
fil.Sort; {sort the lines in ascending order}
fil.savetofile('sorted.txt'); {save them to a file }
FreeAndNil(fil); {free the list}
end. {end of main block}