Skip to main content
1 of 3
terdon
  • 252.2k
  • 69
  • 480
  • 718

Here's another way:

grep -vf new.txt old.txt | tee -a new.txt 

The -v flag tells grep to print lines that do NOT match the pattern given, and the -f new.txt tells grep to use the lines in te file new.txt as the pattern to search for. So grep -vf new.txt old.txt means "show me all lines in old.txt that are missing from new.txt.

We then pipe this to tee with the -a flag which means "append", and tell it to add these lines to new.txt.

terdon
  • 252.2k
  • 69
  • 480
  • 718