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
date format ali560045 Shell Programming and Scripting 4 01-25-2008 04:11 AM
Date Format biju.mp UNIX for Dummies Questions & Answers 2 12-31-2007 06:56 AM
date issue-find prevoius date in a patricular format bsandeep_80 UNIX for Advanced & Expert Users 3 11-15-2007 05:42 PM
convert mmddyy date format to ccyyddd format?? Bhups Shell Programming and Scripting 2 09-27-2006 08:30 PM
date format big123456 Shell Programming and Scripting 2 07-22-2005 01:57 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-10-2008
ali560045's Avatar
Registered User
 

Join Date: Oct 2007
Posts: 265
help in date format

i have written a script that will grep all the file that run for the current date
i,e today's date

for i in *.log
do
if
a=`date +"%b %d"`

then
ls -ltr | grep $a | tr -s " " | cut -d " " -f6-9
else
echo " "
fi
done
------------------------------------------------------------------------------

these are the apps

-rwxr-xr-x 1 pipe pipe 451 Dec 25 23:54 searchstring
-rwxr-xr-x 1 pipe pipe 179 Dec 26 00:38 filesize
-rwxr-xr-x 1 pipe pipe 89 Dec 26 01:08 revint
-rwxr-xr-x 1 pipe pipe 2126 Jan 9 04:57 wordgame
-rw-r--r-- 1 pipe pipe 1871 Jan 9 06:00 sqlnet.log
-rwxr-xr-x 1 pipe pipe 791 Jan 10 01:24 apps
-rw-r--r-- 1 pipe pipe 1969 Jan 10 01:24 perst
-rw-r--r-- 1 pipe pipe 11020 Jan 10 02:45 core
-rwxr-xr-x 1 pipe pipe 144 Jan 10 03:07 d1
---------------------------------------------------------------------------------------------------------------
i want my script to grep the file according to the current date that is jan 10.the desired o/p should be

Jan 10 01:24 apps
Jan 10 01:24 perst
Jan 10 02:45 core
Jan 10 03:07 d1


---------------------------------------------------------------------

but in this script i cnt grep those files that are running for todays date .its showing me all the file which has benn last modified.

i want to grep only those file which has been modified for current date....plz help me in this

Last edited by ali560045; 01-10-2008 at 03:19 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 01-10-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
you can use find
Code:
# find . -type f -name "*.log" -mtime -1 -ls
Reply With Quote
  #3  
Old 01-10-2008
ali560045's Avatar
Registered User
 

Join Date: Oct 2007
Posts: 265
can u please show me the code where to use un my script. actually i m not so aware of unix commands. if u dnt mind can u show me the code
Reply With Quote
  #4  
Old 01-10-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
did you try running the find command? you can use back your method , like cut , to get what you want.
Reply With Quote
  #5  
Old 01-10-2008
ali560045's Avatar
Registered User
 

Join Date: Oct 2007
Posts: 265
its not helping.find is not working...............

i know some problem is there in my ls -ltr logic........can u help me.its showing the previous date o/p also that is yesterday

90113 4 -rwxr-xr-x 1 pipe pipe 791 Jan 10 01:24 ./apps
90114 4 -rw-r--r-- 1 pipe pipe 1969 Jan 10 01:24 ./perst
90116 4 -rwxr-xr-x 1 pipe pipe 179 Jan 10 04:24 ./filesize
90118 4 -rwxr-xr-x 1 pipe pipe 2126 Jan 9 04:57 ./wordgame
90120 4 -rw-r--r-- 1 pipe pipe 1871 Jan 9 06:00 ./sqlnet.log
90121 12 -rw-r--r-- 1 pipe pipe 11020 Jan 10 02:45 ./core
90122 4 -rwxr-xr-x 1 pipe pipe 122 Jan 10 04:26 ./d1

Last edited by ali560045; 01-10-2008 at 03:28 AM.
Reply With Quote
  #6  
Old 01-10-2008
Registered User
 

Join Date: Nov 2007
Posts: 1
Help in date format

Hi

Try this....


ls -ltr | grep -F "Jan 3" | tr -s " " | cut -d " " -f6-9

Specify the date inside quotes of grep -F.

Or

a=`date "+%b %e"`

ls -ltr | grep -F "$a" | tr -s " " | cut -d " " -f6-9

Last edited by karunakaran; 01-10-2008 at 06:05 AM. Reason: To optimise command
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:23 AM.


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

Content Relevant URLs by vBSEO 3.2.0