Hello,
I have two files of the following form. I would like to remove from File.A where the first three colum matches values in File.B to give the output in File.C
File.A
121 54321 PQR CAT
122 765431 ABC DOG
124 98765 ZXY TIGER
125 86432 GEF LION
File.B
122 765431 ABC
125 86432 GEF
I would like my output to be:
File.C
121 54321 PQR CAT
124 98765 ZXY TIGER
Thank you for your input!
Gussi
Hello Gussifinknottle,
Could you please try following and let me know if this helps you.
awk 'FNR==NR{a[$1]=$0;next} !($1 in a)' File.B File.A
Thanks,
R. Singh
RudiC
December 1, 2017, 9:39am
3
To test for first THREE columns as specified, try
awk '{IX = $1 $2 $3} FNR == NR {T[IX] = $0; next} !(IX in T)' file2 file1
1 Like
If it's really as simple as this format and you can be sure that you won't get false matches hiding some of your desired output, would you be okay with a grep command?
Perhaps this will do it for you:-
grep -vf File.B File.A > File.C
I hope that this helps.
Kind regards,
Robin
rudic:
To test for first THREE columns as specified, try
awk '{IX = $1 $2 $3} FNR == NR {T[IX] = $0; next} !(IX in T)' file2 file1
Thanks! @RudiC - I tried and it works :).
@Robin - My data files for the inquiry were for a toy example - the grep does not work (which I tried before posting in the forum)
@R.Singh - I need to test for 3 columns, as @RudiC pointed out.
Thanks all for your input!
~Gussi