Wouldn't use awk, but would use perl instead.
#!/usr/bin/env perl
use strict;
use warnings;
#open both files for reading
open( my $input1, '<', "file1.txt" ) or die $!;
open( my $input2, '<', "file2.txt" ) or die $!;
#read the key-values into a hash called lookup.
my %lookup = do { local $/; <$input1> =~ m/(\d+):(\w+)/g; };
#iterate by line of second file
while ( <$input2> ) {
#trim trailing linefeeds
chomp;
#split current line on :
my ( $user, $key ) = split /:/;
#if exists in original lookup, display record
if ( $lookup{$key} ) {
print join ( ":", $user, $key, $lookup{$key}),"\n";
}
}
I get a slightly different output though - specifically:
bart:29482164591748:computer
smithers:68468468468464:keyboard
lisa:68468468468464:keyboard
I'm not sure why the second 2 shouldn't be printed based on matching key-values.
If you want a one liner that's basically the same:
perl -F: -lane "print $k{$F[0]}.':'.$_ if $k{$F[0]}; $k{$F[1]}//=$F[0];" file2.txt file1.txt
awk?join, IIRC.