simple date problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple date problem
# 1  
Old 01-21-2008
simple date problem

i have a script that grep for today date

a=`date +"%F"`--------greps current/today date

wat if suppose i want to grep a date for yesterday...

how to do that using the above format: i,e 2008-01-20
# 2  
Old 01-21-2008
For cshell,
Quote:
setenv TZ `date +%Z+24` ; date +%Y-%m-%d
Ksh,
Code:
 TZ=`date +%Z`+24 ; date +%Y-%m-%d

Thanks
Nagarajan G
# 3  
Old 01-21-2008
thanks a lot for ur reply........
i have use ur command like this

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

echo $ a

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

i m able to grep yesterday date...can u tell me how to grep 2 day ago and also 3 day ago and likewise in the same format in the above command
# 4  
Old 01-21-2008
Quote:
Originally Posted by ali560045
thanks a lot for ur reply........
i have use ur command like this

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

echo $ a

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

i m able to grep yesterday date...can u tell me how to grep 2 day ago and also 3 day ago and likewise in the same format in the above command
The point is we can achieve it by modifying the TZ variable.
If you need yesterday's date then we advance TZ by 24,similarly for 2 days ago advance TZ by 48 ...
For future dates,we ll reduce the TZ by the 24 for 1 day,48 for 2 days and so on..

Thanks
Nagarajan
# 5  
Old 01-22-2008
thanks again to u.now i m able to grep 1 day ago date and likewise in that format.

i need one more help.

TZ=`date +%Z`+48 ; 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.....

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`+48 ; 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Simple 'date' to 001 scheme script

So since I'm looking for an easy way to numberize files in a folder according to date: Is there an easy script (batch, windows), that will rename files like this: .earliest creation time: 001.file older creatiin time : 002.file even older time : 003.file .... ... .. . ... (10 Replies)
Discussion started by: pasc
10 Replies

2. Shell Programming and Scripting

How to do simple date (time) calculation in shell script?

Hi, I'm looking for a way to do a simple math calc during a shell script as a means of logging how long a particular task takes. For example... STARTTIME=whenever this script starts ./path/to/command.sh >>logfile.log TOTALTIME=<time at this stage of the script after above command... (7 Replies)
Discussion started by: nbsparks
7 Replies

3. Shell Programming and Scripting

Simple date issue

Hi , Here is the smaller version of the problem. Working individually as command ************************>echo $SHELL /bin/bash ************************>TO_DAY=`date` ************************>echo $TO_DAY Tue Jul 16 02:28:31 EDT 2013 ************************> Not working when... (5 Replies)
Discussion started by: Anupam_Halder
5 Replies

4. Shell Programming and Scripting

Simple date and time calulation in BASH

There is a closed Thread: <url>Here will be the url to the original post once I have 5 posts in this forum...</url> But a small bug had found his way into this very cool and simple code. #!/bin/bash date2stamp () { date --utc --date "$1" +%s } stamp2date (){ date --utc --date... (2 Replies)
Discussion started by: frood
2 Replies

5. Shell Programming and Scripting

20090620231013 to date format i am using substr, any simple way in perl?

Hi Everyone, $tmp="20090620231013"; $tmp = substr($tmp,0,8)." ".substr($tmp,8,2).":".substr($tmp,10,2).":".substr($tmp,12,2); So my output is: 20090620 23:10:13. I only can think substr is easy, any perl can do this just one line very simple efficient one? :eek: Thanks (3 Replies)
Discussion started by: jimmy_y
3 Replies

6. Shell Programming and Scripting

Simple date issue

Hi all, i have used the search already before someone shouts at me and i have seen the 'datecalc' program but this is not working correctly for me in the shell and environment i am using. I am using solaris 10 and bourne shell. I have two dates '07-04-2009' and '05-05-2009'. I just need to... (2 Replies)
Discussion started by: muay_tb
2 Replies

7. Shell Programming and Scripting

Simple date formatting?

Hi guys, I have some embedded perl within my shell script to get me the modification time/date of a file which returns me the following string: Fri May 1 09:52:58 2009 I have managed to get the bits i need such as 1-May-2009, but what i would prefer is 010509 instead... Here is my... (4 Replies)
Discussion started by: muay_tb
4 Replies

8. UNIX for Dummies Questions & Answers

Any simple method to check date format (YYDDD)?

Hi Guru's, Are there any simple method to check the date format which is in "YYDDD" (ex: 08002 for 02-Jan-2008)? Eventhough this can be implemented in several way's, I need the simpler one. Any idea would be much appreciated. Thanks in advance, Mysore Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

9. HP-UX

a simple way of converting a date in seconds to normal date

Hi all! I'm working on a HPUX system, and I was wondering if there is a simple way to convert a date from seconds (since 1970) to a normal date. Thanks (2 Replies)
Discussion started by: travian
2 Replies

10. Tips and Tutorials

Simple date and time calulation in BASH

The GNU date command in full of goodies but not when it comes to calculate a date or time difference. Here is what I came up with after looking to more than one solution. Code should be self explaining. #!/bin/bash date2stamp () { date --utc --date "$1" +%s } stamp2date (){ ... (0 Replies)
Discussion started by: ripat
0 Replies
Login or Register to Ask a Question