-8

I have two files, test1 and test2. I would like to compare the files and remove any entries in test2 that are already present in test1.

Example:

test1

[ostrich@post-om1 test]$ cat test1|head
917010023586,UPE,RED 399
917023895388,UPE,RED 499
917023895389,UPE,RED 699
917024120800,UPE,RED 399
917024214387,UPE,RED 399
917027011096,UPE,RED 399
917027120457,UPE,RED 399
917027749420,UPE,RED 399
917030002266,UPE,RED 399
919389105220,UPE,RED 399

test2

[ostrich@post-om1 test]$ cat test2|head
917310106487
919839063308
917081106519
919389105220
919336429543
917081102867
919919804079
919936432138
919455329240
919839601519

Desired output

[ostrich@post-om1 test]$ cat test1
917010023586,UPE,RED 399
917023895388,UPE,RED 499
917023895389,UPE,RED 699
917024120800,UPE,RED 399
917024214387,UPE,RED 399
917027011096,UPE,RED 399
917027120457,UPE,RED 399
917027749420,UPE,RED 399
917030002266,UPE,RED 399
3
  • 2
    show what you've tried... see stackoverflow.com/questions/38739213/… for similar question
    – Sundeep
    Dec 2, 2017 at 14:06
  • This question "title" is an impudence. Dec 2, 2017 at 14:10
  • "remove any entries in test2 that are already present in test1" – Your example output doesn't remove anything from test2; it removes lines from test1... Dec 2, 2017 at 15:02

2 Answers 2

2

I need nine more characters...

grep -vFf test2 test1
0

I achieved above result by below command and it worked fine


awk -F ","  'NR==FNR {a[$1];next}!($1 in a) {print $0}' test2 test1

Not the answer you're looking for? Browse other questions tagged or ask your own question.