0

I have a Masters.txt (all records) and a New.txt file. I want to process New.txt against Masters.txt and output all the lines from New.txt that do not exist in Masters.txt

i'm not sure if this is something the sort -u command can do.

acctman
  • 4,229
  • 30
  • 98
  • 142

2 Answers2

2

Sort both files first using sort and then use the comm command to list the lines that exist only in new.txt and not in masters.txt. Something like:

sort masters.txt >masters_sorted.txt
sort new.txt >new_sorted.txt
comm -2 -3 new_sorted.txt masters_sorted.txt

comm produces three columns in its output by default; column 1 contains lines unique to the first file, column 2 contains lines unique to the second file; column 3 contains lines common to both files. The -2 -3 switches suppress the second and third columns.

Tamás
  • 47,239
  • 12
  • 105
  • 124
0

see the linux comm command:

http://unstableme.blogspot.com/2009/08/linux-comm-command-brief-tutorial.html

momeara
  • 1,341
  • 2
  • 17
  • 29