# save the below code to a file named as "map.awk"
# start from here
BEGIN{
   FS=OFS="|";
   while(getline<ARGV[0]>1)
   {
     arr[$1]=$0
   }
   delete ARGV[0];
}
{
if($5 in arr)
print $0 FS arr[$5]
else
print $0 FS
}
#end here
Run the file as below
nawk -f map.awk file1 file2 > file3
File3 will have all the rows from file2 along with column1 of the file1 where ever column5 of file2 matches.

No comments:
Post a Comment