The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple Script mojoman Shell Programming and Scripting 6 05-12-2008 12:55 AM
simple script ali560045 Shell Programming and Scripting 1 01-22-2008 12:41 AM
Simple Script Help Skunkie UNIX for Dummies Questions & Answers 4 10-02-2006 08:18 AM
simple awk script... moxxx68 Shell Programming and Scripting 3 01-24-2005 12:17 AM
simple script hedrict UNIX for Dummies Questions & Answers 4 02-23-2004 12:15 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-23-2008
ali560045's Avatar
Registered User
 

Join Date: Oct 2007
Posts: 206
Stumble this Post!
simple script help

TZ=`date +%Z`+24 ; a=`date +%Y-%m-%d`-----------greps 1 day ago date........

but this command greps date in files for 1 day ago date........even the current date is found inside the file.....

is there any logic using this command that it will grep the last date entry made in file ,whether it is current date or 1 day ago date or 2 day and likewise ?

here is the script
---------------------------------------------------

TZ=`date +%Z`+24 ; a=`date +%Y-%m-%d`

for i in *.log*
do
echo "Processing for $i"
count=0
count=`cat $i | grep $a | wc -l`
echo $i >> file1.txt
echo "the last date entry made in file1 is $a" >> file1.txt

done
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-23-2008
Registered User
 

Join Date: May 2006
Posts: 44
Stumble this Post!
Hello,

Yiou can find out the latest day and month by using the following command :

day=`ls -lrt *.log | tail -1 | awk '{printf("%2d",$7)}'`
mon=`ls -lrt *.log | tail -1 | awk '{print $6}'`

for file in `ls -l *.log | grep "$mon $day"
do
...

done
Reply With Quote
  #3 (permalink)  
Old 01-24-2008
ali560045's Avatar
Registered User
 

Join Date: Oct 2007
Posts: 206
Stumble this Post!
i need to check the dates inside the file by using the command


cat filename | grep date
Reply With Quote
  #4 (permalink)  
Old 01-24-2008
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Stumble this Post!
Quote:
Originally Posted by ali560045 View Post
i need to check the dates inside the file by using the command


cat filename | grep date
I couldn't get your question,by the way why "cat filename | grep date" while "grep date filename" can do the same job much efficiently?

Thanks
Nagarajan G
Reply With Quote
  #5 (permalink)  
Old 01-24-2008
ali560045's Avatar
Registered User
 

Join Date: Oct 2007
Posts: 206
Stumble this Post!
i checked that way ,but thats not the effective way in my case....

actually my files will contain some dates in it in the format y-m-d.so i need to do

cat filename | grep "the latest date"

i have to go inside the file to serch the latest date.......

so asking how to grep the latest date inside file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0