HI All

I have a script which counts how many times a job has failed.
For some reason my echo $list wont work in a variable, it works if i dont put it in a variable, but i need this in a variable so i can do a grep -c against another file.

Any help would be appreciated.

#!/usr/bin/ksh

set -x

cat /apps/tech/testruniquefailures | while read list ; do
JOBNAME=`echo $list`
Num=`grep -c $JOBNAME /apps/tech/testfailures1`
if [ $Num -gt 0 ] ; then
print $JOBNAME has failed $Num times >> /apps/tech/jinfo.txt
fi
done

This is the output with debug

+cat /apps/tech/testruniquefailures
+read list
+JOBNAME=echo
++ grep -c /apps/tech/testfailures1
Num=0
+ [ - -gt 0 ]
+read list

Ok the issue i have worked out is when there seems to be a space on the new line on the file.

i.e.

cat apps/tech/testruniquefailures
<space is here>
batchjob1
batchjob2

How do i make sure the above file does not have a space on the top of it.

Ok the issue i have worked out is when there seems to be a space on the new line on the file.

i.e.

cat apps/tech/testruniquefailures
<space is here>
batchjob1
batchjob2

How do i make sure the above file does not have a space on the top of it.

don't use useless cat with while loop

while read -r line
do
 #processing
done < "file"

'

anyway, here's another way to solve your problem

# more file
C
D
# more file1
A
B
C
D
E
C
D
C
D
A

# grep -f file file1 | sort | uniq -c
      3 C
      3 D

Grepping and sorting should do it for your script.

It looks like the file you have a blank space in is already assumed to exist in this script (doesn't get created in it).

Do you know what other script (or program) creates the file? That might be the easiest way to prevent the blank line from appearing at the top if you don't want it there.

It's probably a good idea, if that happens enough, to include some functionality in your code to strip blank lines before you parse the file.

Otherwise, the above posted answers are both good ways to deal with your issue.

, Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.