tmd1332
Technical User
- Feb 10, 2010
- 4
Hi Guys. Hoping you can help me. I've been scripting forever, but this one has me stumped.
File1 Contents:
Job: ZDUMM2 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed
Job: ZDUMM1 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed
File2 Contents:
Job: ZDUMM1 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed
Notice the record in File2 exist in File1 also.
From the command line, this Returns a RC:0 as it should
grep "Job: ZDUMM1 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed" File1
Job: ZDUMM1 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed
$ echo $?
0
But when scripted in a loop, no matter what I do, the grep always returns a RC:1.
I've tried every combination of quotes, single, double, escaping the quotes, enclosing single quotes
inside of double quotes. Not matter what I do I get RC:1
This should be something simple, but it's got me stumped.
I've also tried egrep and fgrep. Same results
Here's my simple (but not working) script:
#!/usr/bin/ksh
#set -x
cat File2 | while read record;do
grep "$record" File1
if [ $? -eq 0 ];then
echo "Found it."
fi
done
File1 Contents:
Job: ZDUMM2 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed
Job: ZDUMM1 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed
File2 Contents:
Job: ZDUMM1 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed
Notice the record in File2 exist in File1 also.
From the command line, this Returns a RC:0 as it should
grep "Job: ZDUMM1 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed" File1
Job: ZDUMM1 StDate: 20131114 StTime: 045241 Server: vq2ua740_ECQ_00 Status: Failed
$ echo $?
0
But when scripted in a loop, no matter what I do, the grep always returns a RC:1.
I've tried every combination of quotes, single, double, escaping the quotes, enclosing single quotes
inside of double quotes. Not matter what I do I get RC:1
This should be something simple, but it's got me stumped.
I've also tried egrep and fgrep. Same results
Here's my simple (but not working) script:
#!/usr/bin/ksh
#set -x
cat File2 | while read record;do
grep "$record" File1
if [ $? -eq 0 ];then
echo "Found it."
fi
done