1

I have the following situation:

The file1.dat is like:

1 2
1 3
1 4
2 1

and the file2.dat is like:

1 2
2 1
2 3
3 4

I want to find the differences between the second file from the first. I tried wit grep -v -f file1 file2 but my real files are bigger than this two and when I tried with it the shell never ended is work.

The result should be:

2 3
3 4

The files are sorted and they have the same number of elements. Any way to find a solution with awk?

Valerio D. Ciotti
  • 1,369
  • 2
  • 17
  • 27

1 Answers1

12

Seems like you want lines in file2 that are not in file1:

$ awk 'FNR==NR{a[$0];next}!($0 in a)' file1 file2
2 3
3 4

However it's simpler to use comm:

$ comm -13 file1 file2
2 3
3 4
Chris Seymour
  • 83,387
  • 30
  • 160
  • 202