Search for names in one list in another and print results

Hi All ,

New to the Bash / Shell programming world and looking for some help

I have two files

1: Contains a list of names :

eg

STEVE
BOB
CRAIG

2: Contains information with those included names but also others that are not in the list

STEVE     USER1    0987
ALUN       USER2   0762
BOB        USER3    9327
CRAIG     USER4     3427

I am looking to Cat the first file then grep the names in that list and output the results from file 2

for i in `cat list1 ` do egrep -i $i list2 ; done 

The above just seems to loop through the second list numerous times until it has reached the end of file 1 without giving me the information

Cheers for the anticipated help

Welcome to the forum.

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

What exactly is going wrong with your code snippet - after having added a semicolon in front of the do ? And, except this being incredibly inefficient. When I run it, it gives me the file2 lines for the names in file1.

Did you consider sth. like

grep -ffile1 file2
STEVE     USER1    0987
BOB        USER3    9327
CRAIG     USER4     3427

?