Code:
$
$ # display the contents of file2
$
$ cat file2
USA , Newyork
USA , California
USA , Sanfransisco
USA , Detroit
USA , Chicago
USA , Kansas
USA , St.Louise
USA , Florida
UK , London
FRANCE , Paris
FRANCE , Marsellie.
INDIA , NewDelhi
INDIA , Mumbai
INDIA , Calcutta
INDIA , Chennai
INDIA , Bangalore
JAPAN , Tokyo
JAPAN , Nagasaki
JAPAN , Hirosima
CANADA , Ottawa
CANADA , Montreal
CANADA , Vancuvor
ARGENTINA , Buenos Aires
BRAZIL , Brassila
BRAZIL , Sao Paulo
ITALY , Rome
NORVEY , Oslo
SPAIN , Madrid
GERMANY , Frankfurt
GERMANY , Munich,
USSR , Moscow
USSR , Laningrad
USSR , Vladvostok
$
$ # display the contents of file1
$
$ cat file1
Abc : 1234 : London
Def : 2456 : Paris
Efg :1456 : Newyork
Fgh : 1324 : Tokyo
Hjk : 5829 : California
Lmn : 7823 : Chicao
Klm : 6472 : Munich
Jkm : 8231 : Franfurt
Acl : 3241 : Hiroshima
Jmp : 2385 : Detroit
Lqm : 4613 : Kansas
$
$ # run a Perl one-liner joining city to country
$
$ perl -lne 'if ($ARGV eq "file2"){/^(\w+)\s*,\s*(\w+)$/; $x{$2}=$1} else {/^.*:\s*(\w+)$/; $_="$_ , $x{$1}"; s/:/,/g; print}' file2 file1
Abc , 1234 , London , UK
Def , 2456 , Paris , FRANCE
Efg ,1456 , Newyork , USA
Fgh , 1324 , Tokyo , JAPAN
Hjk , 5829 , California ,
Lmn , 7823 , Chicao ,
Klm , 6472 , Munich ,
Jkm , 8231 , Franfurt ,
Acl , 3241 , Hiroshima ,
Jmp , 2385 , Detroit , USA
Lqm , 4613 , Kansas , USA
$
$