0

I have two TXT files as

#1.txt
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
5.5.5.5

#2.txt
1.1.1.1
2.2.2.2
6.6.6.6
7.7.7.7
8.8.8.8

I made comparison of 1.txt to 2.txt and get the IPs which is not in 2.txt when comparing with 1.txt . I did,

#comm -2 -3 <(sort 1.txt) <(sort 2.txt) > Out.txt

Output

#Out.txt
3.3.3.3
4.4.4.4
5.5.5.5

The Out.txt IPs are the IPs not in 2.txt file.

Now,I would like compare 1.txt against 2.txt and get the one which is not unique from 1.txt .

#1.txt
1,1.1.1.1
2,2.2.2.2
3,3.3.3.3
4,4.4.4.4
5,5.5.5.5

#2.txt
1.1.1.1
2.2.2.2
6.6.6.6
7.7.7.7
8.8.8.8

Expected Result

#Out.txt
3,3.3.3.3
4,4.4.4.4
5,5.5.5.5

How to include IDs in my output result ?

Arun
  • 1,160
  • 3
  • 17
  • 33
  • `I would like compare 1.txt against 2.txt and get the one which is not unique from 1.txt ` don't understand, why `11111` not in output? four 1s and five ones are different aren't they? – Kent Feb 10 '16 at 09:45
  • 1
    oh, I see, it is **comma**! – Kent Feb 10 '16 at 09:46

1 Answers1

1

this awk one-liner should work for your example:

awk -F, 'NR==FNR{a[$0];next}!($2 in a)' 2.txt 1.txt
Kent
  • 189,393
  • 32
  • 233
  • 301