How to remove common lines between two files without sorting? [duplicate]
问题 This question already has answers here : Compare 2 files and remove any lines in file2 when they match values found in file1 (4 answers) Closed 5 years ago . I have two files not sortered which have some lines in common. file1.txt Z B A H L file2.txt S L W Q A The way I'm using to remove common lines is the following: sort -u file1.txt > file1_sorted.txt sort -u file2.txt > file2_sorted.txt comm -23 file1_sorted.txt file2_sorted.txt > file_final.txt Output: B H Z The problem is that I want to