IF statement dealing with current time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting IF statement dealing with current time
# 1  
Old 08-10-2012
IF statement dealing with current time

Hi Guys,

I am trying to put together a script that will search a txt file for a timestamp and select all text after the initial one up to EOF but the timestamp searched for will depend on the current date

So if it the current time is between 0600 and 0700 the script will search a text file (currently open) for a timestamp in the form of YY/MM/DD(yesterdays date)HH:MM that is AFTER 1900 and up to the current date and time. If it finds a stamp within that window it should select all text from that stamp to EOF.
The other case is, if the current time is between 1800 and 2000 then the script should search for a timestamp in the same format but on today's date.
Then if it finds one it should select all text from that timestamp up and to EOF

Something like:
If ( 06:00>Now()<=07:00
then (search for YY/MM/DD HH:MM > YY/MM/DD(-1) 19:00)
if (search finds match)
select all up to EOF
else exit
else ( search for YY/MM/DD HH:MM > YY?MM/DD 07:00)
if (search finds match)
select all to EOF

Sorry for the above but it is (for me ) the easiest way to explain my needs!

After the selection is made I think I know how to print it to a new file but not 100% sure.

For now if I can make the required selection based on the terms I would be more than happy.
Any help would be appreciated greatly!

TIA
# 2  
Old 08-10-2012
From what i understand that u want to run script in between 06 - 07..
so u can run through crontab...

and to get yesterday's date

Code:
date --date="yesterday"

to add your required time format just append to to above code..

Code:
date --date="yesterday" +%Y/%m/%d_%H:%M

# 3  
Old 08-10-2012
Thanks very much for the quick response pamu!

That has some very helpful info but one thing,
How to I search so that it will look for the date and time AFTER a given DATE + TIME?

So the timestamp could be anywhere from yesterday @ 1900 up to now (between 0600 and 0700) so when it finds it it should select all text in file after.

Thanks!
# 4  
Old 08-10-2012
Quote:
Originally Posted by martin0852
Thanks very much for the quick response pamu!

That has some very helpful info but one thing,
How to I search so that it will look for the date and time AFTER a given DATE + TIME?

So the timestamp could be anywhere from yesterday @ 1900 up to now (between 0600 and 0700) so when it finds it it should select all text in file after.

Thanks!
Could you please provide me the input file format...... or some input....
# 5  
Old 08-10-2012
I have attached the file I want to pull the text from...
So this would be run between 06:00 and 07:00 and from the file I want anything done after 19:00 the previous day.
So the first set of action up to the action started at 01:33 "this morning" should not be pulled, just the actions timestamped after 19:00 yesterday,
Thanks!
# 6  
Old 08-10-2012
To search from yesterdays date after 19.00 ... use this..
It will print all the lines after the match found...
Code:
search_var=$(echo "`date --date="yesterday" +%Y-%m-%d`  19:")

sed '1,/'"$search_var"'/d'

This User Gave Thanks to pamu For This Post:
# 7  
Old 08-10-2012
Hi Pamu,

I put this in as a shell command but get a warning saying Variable syntax search_var:undefined variable

If this is something to do with defining the file to search then I'm not sure how to fix it.

I am running the script as a shell_command in NEDIT so the script will be running on the currently opened file.

Also, will this just search for everything between 19:00 and 20:00??

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adjustment to current awk statement

Hello all, I have a script that currently works very well but I would like to make a change so that I could prompt for user input for a 2 digit numeric field that would represent the month instead of using the system date for the month. This is my current awk script that Don so graciously... (1 Reply)
Discussion started by: ziggy6
1 Replies

2. Shell Programming and Scripting

Convert UTC time into current UNIX sever time zone

Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone. For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
Discussion started by: mohanalakshmi
5 Replies

3. Shell Programming and Scripting

To get the time exactly 24hrs from the current time

Hi guys, I am having file which contains below data. 2012-04-24 08:40:13 10739022730 1027699274PersonInfoShipTO details missing FirstName,LastName, 2012-04-24 08:40:13 10739022730 1027699274PersonInfoShipTO details missing FirstName,LastName, 2012-04-24 08:40:13 ... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

4. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

5. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

6. Shell Programming and Scripting

How far is given date from current time?

give a date and time: Jun 12 21:05:16 06-12-2012 21:05:16 2012/06/12 21:05:16 How can i subtract these dates and times from the current date and time and get back the difference in seconds? a one liner like: echo "Jun 12 21:05:16" | some perl/awk programming 90900s (2 Replies)
Discussion started by: SkySmart
2 Replies

7. Shell Programming and Scripting

unziping to current time stamp

Basically when ever unzipping the .zip file , what ever the file exist in the .zip file with the time stamp, that is the same time stamp after unzip. But if i need the current time stamp to the unzipped file(time stamp whenever unzip process occurs ) any helpful option in unzip command ??? ... (4 Replies)
Discussion started by: posix
4 Replies

8. Shell Programming and Scripting

Need help for AWK output with current time

Hi, Any suggestion to get the AWK output with time in each line ? I want to have the vmstat in solaris with time append to everyline like this: kthr memory page disk faults cpu r b w swap free re mf pi po fr de sr s0 s1 s3 sd in sy cs... (2 Replies)
Discussion started by: roxy2k
2 Replies

9. Shell Programming and Scripting

getting hour minus the current time

Can some one help me getting last hour of the current time with date command in a script. (7 Replies)
Discussion started by: shehzad_m
7 Replies

10. Shell Programming and Scripting

Substituting variable with current time

Hi all I have a script as follows :- #!/usr/bin/ksh IDT=`date +"%OH%M%S"` while true do echo ${IDT} sleep 1 done I need the time to show me the current runtime value for the time, however this returns the time as at the start of the script. Any ideas. Thanks JH (4 Replies)
Discussion started by: jhansrod
4 Replies
Login or Register to Ask a Question