一个麻烦的小题: select name,score from a where a.name in (select name from b)

一个麻烦的小题: select name,score from a where a.name in (select name from b)

有两个文本文件,一个存放人名,一个存放人名及分数,例如:
cat  name
john
tom
hero
white

cat score
john 89
tom 32
black 48
white 92
hero 4
tommy 75

问题是将文件score中在name中出现名字的出来,我的做法是编辑一个sed文件:
/joh/ p
/tom/ p
/hero/ p
/white/ p

执行sed -n -f mysed score, 请问dearvoid是否有更好的办法?      
引用:
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; cat file1
john
tom
hero
white
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; cat file2
john    89
tom     32
black   48
white   92
hero    4
tommy   75
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; grep -F -f file1 -w file2
john    89
tom     32
white   92
hero    4
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; bye
      
真是高!i 服了 u!!!      
[QUOTE=TUDOU01]真是高!i 服了 u!!![/QUOTE]
      
dearvoid的水平真没二话      
引用:
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; cat file1
john
tom
hero
white
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; cat file2
john    89
tom     32
black   48
white   92
hero    4
tommy   75
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; cat select.awk
#!/bin/awk -f

BEGIN {
    regexp=""
    while (getline < "file1") {
        regexp = regexp (regexp ? "|" : "") $1
    }
    regexp = "^(" regexp ")$"
}

$1 ~ regexp {
    print
}
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; awk -f select.awk file2
john    89
tom     32
white   92
hero    4
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=24287 $?=0] ; bye
      
grep -w "`awk '{print $1}' name | grep -v "^$"`" score      
引用:
grep -w "`awk '{print $1}' name | grep -v "^$"`" score
fine

      
受这个帖子的启发:
引用:
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=27866 $?=0] ; cat file1
john
tom
hero
white
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=27866 $?=0] ; cat file2
john    89
tom     32
black   48
white   92
hero    4
tommy   75
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=27866 $?=0] ; awk 'NR == FNR { a[$1] = 1 } NR > FNR && a[$1] { print }' file1 file2
john    89
tom     32
white   92
hero    4
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=27866 $?=0] ; bye