If I was right about the goal, here's one way to do it from the command line: $ cat /file/with/just/numbers /file/with/pairs | awk '(NF==1) {seen[$1]=1} (NF==2 && seen[$1]) {print}' -- Mark J. Reed <[log in to unmask]>