Finding differences between 2 text files

Hi everyone,

I know that's a deep treated issue but I'm actually not able to find the solution. I have 2 plain text files with ~ 2000 rows and ~5 columns. The first column of the shortest file (f1) is fully contained by the first column of the biggest one (f2), but only that column. I want to create a third file that would contain all the rows which first column is in f2 but not in f1. I mean:

f1:
aa 111 111

f2:
aa 555 555
bb 666 666
cc 777 777

f3:
bb 666 666
cc 777 777

I've tried to do it with GREP but it doesn't work (I think it's too much sensitive to the spaces so the f3 is not complete). Exactly, what I tried was:

grep -f f1 -v -w f2 > out.list and many others variants like without -w, with -E, -F...

Any ideas?

PS: sorry because of my latenight English, it's kind a late here in Spain :mad:

bash-3.2$ cat f1.txt
aa 111 111
bash-3.2$ cat f2.txt
aa 555 555
bb 666 666
cc 777 777
bash-3.2$ awk '{print "grep -v "$1" f2.txt"}' f1.txt |sh
bb 666 666
cc 777 777

Thanks, but it doesn't work. It seems to be stuck. The size of the output files is extremely large (187 Mb). There are too many rows on it.

Try:

 awk 'NR==FNR{A[$1];next}!($1 in A)' f1 f2

Thank you very much Scrutinizer!! It totally works!

Now there are 1077 galaxies waiting for been examinated.

I owe you one.

Nacho

@Scruti
I don't get that one, could you please explain the code ?
I mean : f1 and f2 ... how awk does know which one it should take and when ?
What is between the simple quote apply to f1 ? or f2 ? or both ?
Why NR==FNR ? to make sure an associative array is set up for all records ? of f2 ?

Hi ctsgnb, NR is only equal equal to FNR when awk is reading the first file.