File1 contains:421 RP-001421 RP-002421 RP-003550 SC-001550 SC-002550 SC-003550 SC-004550 DY-001550 DY-002550 DY-001550 OU-001550 OU-002Script:#!/bin/bashElogs=/home/elogs.txtErrors=/home/errorcodes    for i in `cat $Errors`; do    #Get Error Logs    grep $i /home/eximlog >> $ElogsdoneDebug:       + cat /home/errorcodes+ for i in 'cat $Errors'+ grep 421 /home/eximlog+ for i in 'cat $Errors'+ grep RP-001 /home/eximlog+ for i in 'cat $Errors'+ grep 421 /home/eximlog+ for i in 'cat $Errors'+ grep RP-002 /home/eximlog+ for i in 'cat $Errors'+ grep 421 /home/eximlog+ for i in 'cat $Errors'+ grep RP-003 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep SC-001 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep SC-002 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep SC-003 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep SC-004 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep DY-001 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep DY-002 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep DY-001 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep OU-001 /home/eximlog+ for i in 'cat $Errors'+ grep 550 /home/eximlog+ for i in 'cat $Errors'+ grep OU-002 /home/eximlogWhy loop read all codes like 421 and RP-001 separately. And bring duplicate result. Grep should consider codes a single string like: 421 RP-001And debuging should like this:+ for i in 'cat $Errors'+ grep 421 RP-001 /home/eximlog 
Using Grep In For Loop
bash;shell script;scripting
The shell will perform word splitting on $(cat $Errors).  That is why you get one word at a time instead of one line at a time.You want a while read... loop:while read -r line; do    #Get Error Logs    grep $line /home/eximlog >> $Elogsdone <$Errorsread is line oriented: it reads one line at a time.  Or, this may work for you and it doesn't need any looping at all: grep -f $Errors /home/eximlogThe -f options tells grep to read patterns from a file, one pattern per line.Also, it looks to me like your error code patterns are fixed strings not regular expressions.  In that is the case, to avoid unpleasant surprises, add the -F option to grep: grep -Ff $Errors /home/eximlog