Retreive the records from file2 by using the first field in file1

view story

http://www.unix.com – Hi Freinds, i have a file1 as below file1 Code: 1|ndmf|fdd|d3484|34874 2|jdehf|wru7|478|w489 3|dfkj|wej|484|49894 file2 contains lakhs of records and not in sorted order i want to retrive only the records from file2 by searcing the first field of file 1 i used Code: grep ^1 file2 >out.txt grep ^2 file2 >>out.txt grep ^3 file2>>out.txt this i need to do 3 times . if i have some 1L records in file1 and need to take only matching records , i am struck Please help me i am newbie to shell (HowTos)