Sort and extract based on two files

Hi,

I am having trouble sorting one file based on another file. I tried the grep -f function and failed. Basically what I have is two files that look like this:

File 1 (the list)

gh
aba
for
hmm

File 2 ( the file that needs to be sorted)

aba  2  4  6  7
for   2  4  7  4
hmm  1  2  7  4
gh  2  5  7  9

So file 1 is a list that has names in a particular order and I want to sort file 2 according to that order while also extracting the other columns.

So the end output would look like this.

Final file

gh  2  5  7  9
aba  2  4  6  7
for   2  4  7  4
hmm  1  2  7  4

the file is tab separated.

Thanks

Phil

awk 'NR == FNR {
  data[$1] = $0; next
  }
$1 in data {
  print data[$1]
  }' file2 file1 
egrep -f File1 File2

O/P:

egrep -f file1 file2

aba 2 4 6 7
for 2 4 7 4
hmm 1 2 7 4
gh 2 5 7 9

Hi.

This query was also posted in March, Sort and extract based on two files

Why is it being posted again? ... cheers, drl