sorting the datafile in an order given in second datafile

Hi,

I have two files:

first input file is having 7-8 columns,

and second data file is like

I want to arrange my datafile1 in the order given in second data file, by comparing the seconddatafile with the second column of first file and print the entire line....also if any string (b in this case) is absent..it must print absent in first lane

The output must be like:

Thanks in advance.....

awk 'NR==FNR{a[$2]=$0;next}{print a[$1]?a[$1]:"ABSENT"}' file1 file2
1 a rew sdf ghd 234 gfd 345
ABSENT
7 c dns esd lkn 765 nkc 093
4 d bhj asd klj 231 kljn 211
ABSENT
3 f hjk kln ghj 879 nkj 989
ABSENT
1 Like
nawk 'FNR==NR {f1[$2]=$0;next}{print ($1 in f1)?f1[$1]:"ABSENT"}' firstFile secondFile
1 Like