Hey why going for a awk solution when you can simply use the following join command:
join -t':' file 1 file2
where join as its names indicate is just a file joining command and you chose the field separator and usually the input columns and output to display (here not necessary)
Tested:
$more file{1,2}
::::::::::::::
file1
::::::::::::::
[email protected]
[email protected]
[email protected]
::::::::::::::
file2
::::::::::::::
[email protected]:addressotest
[email protected]:clubbingson
[email protected]:addresso2
$join -t':' file1 file2
[email protected]:addressotest
[email protected]:addresso2
If you need to sort the output as well, change the command into:
join -t':' file 1 file2 | sort -t":" -k1
or
join -t':' file 1 file2 | sort -t":" -k2
depending on which column you want to sort upon (eventually add the -r option to sort in reverse order.
join -t':' file 1 file2 | sort -t":" -k1 -r
or
join -t':' file 1 file2 | sort -t":" -k2 -r
awk -F: [your code here] file1 file2.