I have two files and need to compare the two files and to remove the matching lines from both the files
awk '{arr[$0]++} END {for (i in arr) {if (arr>1) {print $0} }} ' file1 file2 > dupfile
awk 'FILENAME=="dupfile" {arr[$0]++}
FILENAME=="file1" {if ($0 in arr) {next} else {print $0 >"newfile1"}}
FILENAME=="file2" {if ($0 in arr) {next} else {print $0 >"newfile2"} }' dupfile file1 file2
Not tested.
Try this...
awk '{ if (FNR==NR) {arr[$0]++;next}
if ($0 in arr) { arr[$0]--; if (arr[$0] == 0) delete arr[$0]; next}
{print $0 >"newfile2"} }
END {for (i in arr) {print i >"newfile1"} } ' file1 file2
Jim: The code you have given has potential to remove duplicate lines in one file even though no matching record present in other file because those lines has multiple instances in a single file.
I also have this kind of problem. The code above deletes the lines which are alike on the two files. How can i do this, on a separate file?
File 3:
#from first file
a3px lm4 xpm
0wmp jga1 wmp6
#from second file
a3px lm4 xpj
0xmp lm4 xpm
thanks a lot!
maybe?
awk '! LINE[$0] { print; LINE[$0] = $0}' in_file