👤
Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

To run a script based on the value in text file

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 12-29-2010
Java To run a script based on the value in text file

I have a Text file as shown below
/* text file begins----------
Code:
----------- 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.

Moderator's Comments:
To run a script based on the value in text file Please use code tags when posting data and code samples!

Last edited by Franklin52; 12-29-2010 at 12:30 PM..
# 2  
Old 12-29-2010
I suggest:
Code:
grep -q 'Sum of reject_files= *0$' inputfile && command...

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

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

grep is your friend :-)
# 3  
Old 12-29-2010
'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
# 4  
Old 12-29-2010
Something like this,


Code:
#!/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

# 5  
Old 12-29-2010
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:
Code:
Sum of reject_files=0

or
Code:
Sum of reject_files=                        0

(ok, I added lots of whitespace for emphasis).
# 6  
Old 12-29-2010
@ pravin
hi pravin, just iam new to unix
can u please explain
rej_cnt=`echo $LINE|awk '{print $4}'`

thnk U bro
# 7  
Old 12-29-2010
Sorry, I thought your requirement is to read each line from the file and if reject count is zero then run your script.
Code:
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,

Code:
 var=`awk -F"=" '/Sum of reject_files/ {print $2 == 0 ?1:0}' inputfile` ; [[ $var == 1 ]] && echo "run script"

👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To run the script based on dates rohit_shinez Shell Programming and Scripting 9 12-08-2017 02:08 AM
Delete records based on a text file from a text file tech_frk UNIX for Dummies Questions & Answers 3 10-03-2014 05:32 AM
How to delete lines of a text file based on another text file? prvnrk Shell Programming and Scripting 2 03-07-2013 09:35 PM
Extracting lines from a text file based on another text file with line numbers evelibertine UNIX for Dummies Questions & Answers 1 12-11-2012 03:39 PM
Need to check links exists in the server based on that need to run the build script muraliinfy04 Shell Programming and Scripting 1 04-26-2012 04:27 AM
run the file based on environment moe458 Shell Programming and Scripting 5 09-30-2011 12:21 PM
Script for replacing text in a file based on list phoenixjc UNIX for Dummies Questions & Answers 8 09-29-2010 12:20 PM
Run a script based on the subject line of the email satekn Shell Programming and Scripting 5 04-16-2009 12:11 PM
Bash script to delete folder based on text file information bone11409 Shell Programming and Scripting 8 01-16-2009 11:22 AM
trigger a script based on the run status of another scipt Athena Shell Programming and Scripting 1 10-02-2008 02:11 PM


All times are GMT -4. The time now is 02:28 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password