Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-29-2010   -   Original Discussion by nani1984
nani1984's Unix or Linux Image
nani1984 nani1984 is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 18 November 2014, 11:18 AM EST
Posts: 44
Thanks: 6
Thanked 0 Times in 0 Posts
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..
Sponsored Links
    #2  
Old Unix and Linux 12-29-2010   -   Original Discussion by nani1984
m.d.ludwig's Unix or Linux Image
m.d.ludwig m.d.ludwig is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 7 December 2012, 7:50 PM EST
Location: Albany, NY
Posts: 313
Thanks: 15
Thanked 60 Times in 60 Posts
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 :-)
Sponsored Links
    #3  
Old Unix and Linux 12-29-2010   -   Original Discussion by nani1984
nani1984's Unix or Linux Image
nani1984 nani1984 is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 18 November 2014, 11:18 AM EST
Posts: 44
Thanks: 6
Thanked 0 Times in 0 Posts
'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 Unix and Linux 12-29-2010   -   Original Discussion by nani1984
pravin27's Unix or Linux Image
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 21 June 2017, 2:44 PM EDT
Location: ./India/Bangalore
Posts: 1,271
Thanks: 70
Thanked 299 Times in 290 Posts
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

Sponsored Links
    #5  
Old Unix and Linux 12-29-2010   -   Original Discussion by nani1984
m.d.ludwig's Unix or Linux Image
m.d.ludwig m.d.ludwig is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 7 December 2012, 7:50 PM EST
Location: Albany, NY
Posts: 313
Thanks: 15
Thanked 60 Times in 60 Posts
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).
Sponsored Links
    #6  
Old Unix and Linux 12-29-2010   -   Original Discussion by nani1984
nani1984's Unix or Linux Image
nani1984 nani1984 is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 18 November 2014, 11:18 AM EST
Posts: 44
Thanks: 6
Thanked 0 Times in 0 Posts
@ pravin
hi pravin, just iam new to unix
can u please explain
rej_cnt=`echo $LINE|awk '{print $4}'`

thnk U bro
Sponsored Links
    #7  
Old Unix and Linux 12-29-2010   -   Original Discussion by nani1984
pravin27's Unix or Linux Image
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 21 June 2017, 2:44 PM EDT
Location: ./India/Bangalore
Posts: 1,271
Thanks: 70
Thanked 299 Times in 290 Posts
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"

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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
Adding a column to a text based on file name rlapate Shell Programming and Scripting 12 05-23-2009 10:22 PM
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 12:05 PM.