If the file is too large to sort in memory, maybe you can use perl to convert it to a format that would lend itself to a normal file sort. Write a program to convert the multiline format to a single line format and another program to convert it back. You might even consider writing these programs as filters so the data would just pass through instead of having to create temporary intermediate files.