PROMPT% cat file1
cat
dog
bird
parrot
perl
yakko
wakko
PROMPT% cat file2
cat
bird
perl
parrot
yakko
dot
PROMPT% sort file1 > file1.sort
PROMPT% sort file2 > file2.sort
PROMPT% comm -23 file1.sort file2.sort > only.in.file1
PROMPT% comm -13 file1.sort file2.sort > only.in.file2
PROMPT% cat only.in.file1
dog
wakko
PROMPT% cat only.in.file2
dot
I'll admit, sort isn't the fastest thing in the world for large files, but if you only need to run this once, then comming up with a complicated algorithm (which may or may not have bugs depending on your assumptions about this "N" you mentioned) probably isn't worth it.
|