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

Tags
shell scripts

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 01: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
Creating a text based game using shell script. Othmane Shell Programming and Scripting 3 12-08-2017 11:07 AM
Extract sentence and its details from a text file based on another file of sentences my_Perl Shell Programming and Scripting 7 10-18-2015 06:38 PM
Delete records based on a text file from a text file tech_frk UNIX for Dummies Questions & Answers 3 10-03-2014 06:32 AM
How to delete lines of a text file based on another text file? prvnrk Shell Programming and Scripting 2 03-07-2013 10: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 04:39 PM
How to cut from a text file based on value of a specific column? evelibertine UNIX for Dummies Questions & Answers 4 11-05-2012 07:52 AM
Script for replacing text in a file based on list phoenixjc UNIX for Dummies Questions & Answers 8 09-29-2010 01:20 PM
Delete block of text in one file based on list in another file Festus Hagen Shell Programming and Scripting 3 09-04-2009 12:07 AM
Bash script to delete folder based on text file information bone11409 Shell Programming and Scripting 8 01-16-2009 12:22 PM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-10-2007 03:25 AM


All times are GMT -4. The time now is 09:07 PM.

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