You can use some terrible thing O (n ^ 2) like this (Pseudocode):
file2 = EMPTY_FILE for each line in file1: if not line in file2: file2.append(line)
This is potentially quite slow, especially if it is implemented at the Bash level. But if your files are short enough, it will probably work fine, and will be quickly implemented ( not line in file2 then just grep -v , etc.).
Otherwise, you could, of course, encode a dedicated program using a more advanced in-memory data structure to speed it up.
unwind
source share