I want to match column3 of file1 & column2 of file2 , after that i want to print all column of matching lines in a single line, i know how to do it but the problem is that if there are not unique vales in column2 of file2 then output will be last matching line of file2. but i want that (conflicting) multi matching lines in seperate file & only matching unique line in output file.
example:-
I have two file like these:
file1
abc ram_1 ram1
abc ram[0] ram0
bcd raghu_reg_9 raghu9
cde tanu/8 tanu8
file2
1 ram1
2 thakur56
3 ram0
4 ram1
5 ram2
6 raghu9
7 raghu
I tried awk as:
awk 'FNR==NR{a[$2]=$0;next} { if ($3 in a){print a[$3],$1,$2}}' file2 file1
This gives output as:
4 ram1 abc ram_1
3 ram0 abc ram[0]
6 raghu9 bcd raghu_reg_9
But i want output1 as:
3 ram0 abc ram[0]
6 raghu9 bcd raghu_reg_9
And in output2 as:
1 ram1 abc ram_1
4 ram1 abc ram_1
because there are two entries for ram1 in column2 of file2 & when we match ram1 of column3 of file1 to the ram1 of column2 of file2 then this will match twice & will give 2nd ram1 as output, but i want that if this type of condition arise then these conflicting lines should go to seperate file so that i can manually decide which one should i choose.