To run a script based on the value in text file

I have a Text file as shown below
/* text file begins----------

----------- Monthly files Loaded -------------
input_file record_count load_count reject_count
------------ ----------- ----------- -----------
1_IN.txt 221935 221935 0
2_IN.txt 270668 270668 0
3_IN.TXT 231666 80370 151296
4_IN.txt 148023 148023 0
5_IN.TXT 38399 38399 0
6_IN.txt 377555 377555 0
7_IN.txt 34855 34855 0
 
Sum of reject_files= 151296

-------------------------- text file ends */
Can u suggest me tat how can i catch that " sum of reject_files" in unix.... because
I have to run a script if that value is 0 (ZERO) in the text file.
Want the command to run a script if the value "Sum of reject_files" is 0 in the text file.

I suggest:

grep -q 'Sum of reject_files= *0$' inputfile && command...

or

if grep -q 'Sum of reject files= *0$'; then
    command...
fi

---------- Post updated at 11:09 AM ---------- Previous update was at 11:08 AM ----------

man grep (linux) is your friend :slight_smile:

'Sum of reject files= *0$'
means
wheather 'Sum of reject files contains 0 or starts with 0 .... because u put * infront of 0.... can u plz explain it

Something like this,

#!/bin/sh
while read LINE
do
rej_cnt=`echo $LINE|awk '{print $4}'`
if [ $rej_cnt == 0 ]
then
echo "here you can run your script"
fi
done < inputfile

The " *" means zero or more spaces in front of the "0".
The "$" means ends with "0".

I did not know if the line would be:

Sum of reject_files=0

or

Sum of reject_files=                        0

(ok, I added lots of whitespace for emphasis).

@ pravin
hi pravin, just iam new to unix
can u please explain
rej_cnt=`echo $LINE|awk '{print $4}'`

thnk U bro

Sorry, I thought your requirement is to read each line from the file and if reject count is zero then run your script.

rej_cnt=`echo $LINE|awk '{print $4}'`

The above command will cut the 4th field of your input record and assign it to variable rej_cnt

---------- Post updated at 12:52 PM ---------- Previous update was at 12:33 PM ----------

Try this,

 var=`awk -F"=" '/Sum of reject_files/ {print $2 == 0 ?1:0}' inputfile` ; [[ $var == 1 ]] && echo "run script"
value=$(awk '/Sum of reject_files/ {print $NF}' Text.file)