File1 contains:
421 RP-001
421 RP-002
421 RP-003
550 SC-001
550 SC-002
550 SC-003
550 SC-004
550 DY-001
550 DY-002
550 DY-001
550 OU-001
550 OU-002
Script:
#!/bin/bash
Elogs=/home/elogs.txt
Errors=/home/errorcodes
for i in `cat $Errors`; do
#Get Error Logs
grep "$i" /home/eximlog >> $Elogs
done
Debug:
+ 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/eximlog
Why loop read all codes like "421" and "RP-001" separately. And bring duplicate result. Grep should consider codes a single string like: "421 RP-001"
And debuging should like this:
+ for i in 'cat $Errors'
+ grep 421 RP-001 /home/eximlog