bellaire,
First, I believe your grep usage would need to be modified because as-is, the lines will be treated as regular expressions and not fixed strings. Second, I wonder how this would work if arbitrarily large files need to be supported. For instance, sort resolves this issue by using an on-disk divided and conquer strategy so assuming you have enough free filesystem, you can sort any size file. I just don't know how grep would do in this situation.