Grep using date issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep using date issue
# 8  
Old 01-13-2014
There is no need to open a new thread...
grep and pattern: grep will match whatever pattern you give, you have to find a way to restrict the output, that is don by analyzing more thinly what you want:
As you have seen Bakunin answer, one way to do this when looking for date/time is :
Do I have a space ( or 2 ) before my pattern, if so, include it in the pattern delimited by ", that may be enough...
But you havent given a complet line as sample for us to figure out... So we can only guess and I hate to reply to guesses I already have alot to do...
# 9  
Old 01-13-2014
Moderator's Comments:
Mod Comment There is no point in having two threads for the same question. I am going to merge these two.


@Thread-O/P: Please, if you are asked to clarify your question, do not open a new thread but simply provide the information asked for. It happens to all of us sometimes to forget some vital data (or not to recognize it as indeed vital). The simple solution is to submit it after being asked for. If you open a new thread you are taking in fact away context because many people will not notice the connection between the two threads.

bakunin
# 10  
Old 01-13-2014
Error

Here is just an example: I need to grep for time [23:59] and string [yellow]. It should yield all the lines that contain yellow as well as any time between 23:59:00 to 00:02:00 i.e 23:59 +3 mins.

The grep query should be smart enough to search for all timing between the given time + 3 mins on a 24 hrs clock.

So, in this case if my log file contains the below five lines
Code:
yellow team won at 00:23:59 on monday
red team won at 00:00:43 on monday
yellow team won at 00:01:07 on monday
yellow team won at 00:02:55 on monday
yellow team won at 23:59:23 on monday

Desired output should be
Code:
yellow team won at 00:01:07 on monday
yellow team won at 23:59:23 on monday

Thus my query should be generic for all timings and not just for 23:59.

Kindly help with this complex query !!

Many Thanks.
# 11  
Old 01-14-2014
Quote:
Originally Posted by mohtashims
Here is just an example: I need to grep for time [23:59] and string [yellow]. It should yield all the lines that contain yellow as well as any time between 23:59:00 to 00:02:00 i.e 23:59 +3 mins.

The grep query should be smart enough to search for all timing between the given time + 3 mins on a 24 hrs clock.

So, in this case if my log file contains the below five lines
Code:
yellow team won at 00:23:59 on monday
red team won at 00:00:43 on monday
yellow team won at 00:01:07 on monday
yellow team won at 00:02:55 on monday
yellow team won at 23:59:23 on monday

Desired output should be
Code:
yellow team won at 00:01:07 on monday
yellow team won at 23:59:23 on monday

Thus my query should be generic for all timings and not just for 23:59.

Kindly help with this complex query !!

Many Thanks.
The thing that is complex here is not the query; it is trying to figure out what you're trying to match. The English term "between" (from your requirement in red above) is ambiguous as to whether or not the end points are included. And, since you aren't including the seconds in your starting time, but the seconds value in the end point of your search seems to matter it is even more confusing. When you say:
Quote:
any time between 23:59:00 to 00:02:00 i.e 23:59 +3 mins.
are you referring to the three minutes and one second starting with 23:59:00 up to and including 00:02:00, the three minutes starting with 23:59:00 up to but not including 00:02:00, or the two minutes and 59 seconds starting with 23:59:01 up to but not including 00:02:00?

And, since the RE that you showed us in the original posting in these threads was 23:59.*yellow (which will only match if yellow comes AFTER the timestamp), but your sample input in message #10 in this thread always shows the color BEFORE the timestamp; is the code you want supposed to find the color after a matching timestamp; before a matching timestamp; or anywhere on the line that contains a matching timestamp?

I realize that these seem like picky details; but after more than 200 posts in these forums you should know by now that if the details of your request are not clear, the likelihood of getting working code depends on us guessing at what your real requirements are.

And, you said the time can vary. Will the script you want always only look for yellow, or is the color a parameter to your script as well?

If you had given us clear requirements for your search and sample contents of your file (out.log) in your original posting, we wouldn't still be trying to figure out what you want two days later. Help us help you by giving us a clear set of requirements!
# 12  
Old 01-14-2014
i mean 23:59:01 up to 00:02:00.

Quote:
And, you said the time can vary. Will the script you want always only look for yellow , or is the color a parameter to your script as well?
It will always look for "yellow" not for any other color. It's the time that will vary !!

Last edited by mohtashims; 01-14-2014 at 03:06 AM..
# 13  
Old 01-14-2014
Look at:
Remove lines older than 30 days | Unix Linux Forums | Shell Programming and Scripting
You could adapt the script to your desires about date/time using either 2 pass, or imbricated loops, then use the output produced to grep the colour...
# 14  
Old 01-14-2014
Quote:
Originally Posted by vbe
Look at:
Remove lines older than 30 days | Unix Linux Forums | Shell Programming and Scripting
You could adapt the script to your desires about date/time using either 2 pass, or imbricated loops, then use the output produced to grep the colour...
I gues the thread you directed me to require perl which i don't have.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Date issue

How to compare two input date string? What I am basically trying to get here is get file names in a directory for a particular date range. I would like to get the file data growth over a certain period of time. When below code ran I am getting error - -sh: 20190929: No such file or... (4 Replies)
Discussion started by: vedanta
4 Replies

2. Shell Programming and Scripting

Date issue

I have posted a code last week about that date format problem, well I have figured out a much lesser coding. #!/usr/bin/bash clear export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 if ; then echo " Incorrect Number of Arguments"; echo " Usage : Main_Script <FROM_DATE>... (1 Reply)
Discussion started by: Chandan_Bose
1 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

Calculating expiry date using date,sed,grep

Hi, I would greatly appreciate it if someone can help me with my problem. I have a crawler which collects spam URLs everyday & this data needs to be published in a blacklist. Here's the catch: The "Time To Live" (TTL) for each URL is 3 months (or whatever for that matter). If i see the... (5 Replies)
Discussion started by: r4v3n
5 Replies

5. Shell Programming and Scripting

date printing issue

Hello folks Below command shows current date echo `date +%Y-%m-%d` 2010-04-21 How to show one day old date, i want see like 2010-04-20 (1 Reply)
Discussion started by: learnbash
1 Replies

6. Shell Programming and Scripting

Date issue

Hi I need to write a shell script (bash) that takes a date as an in-parameter an decides if its winter or summer time. I have diffrent dates like 20150112 , 200901028 , 200100605 etc. The rule for winter/summer time is : Summer time spans between the last Sunday in march 02:00 to the... (2 Replies)
Discussion started by: duffnix
2 Replies

7. Shell Programming and Scripting

sort date issue

Hi Everyone, # cat b Sat 12 Sep 2009 10:31:49 PM MYT;a;a;a;Sun 13 Sep 2009 11:32:49 AM MYT; Sat 13 Sep 2009 10:31:49 PM MYT;a;a;a;Mon 14 Sep 2009 10:31:49 PM MYT; Sat 14 Sep 2009 10:31:49 PM MYT;a;a;a;Sun 13 Sep 2009 10:31:49 PM MYT; # sort -t';' -k5 b Sat 13 Sep 2009 10:31:49 PM... (8 Replies)
Discussion started by: jimmy_y
8 Replies

8. Solaris

Cron Date issue

Hi, We have Solaris10.2.3 server. If we execute command `date` on Command Line Promt it shows time - >Tue Jun 23 11:35:55 BST 2009 - which is correct However if the command is executed through cron it gives - >Tue Jun 23 10:35:55 ESTEDT 2009 - which is wrong Request you to help me in... (1 Reply)
Discussion started by: sk2304
1 Replies

9. UNIX for Advanced & Expert Users

date issue-find prevoius date in a patricular format

Hi , I have written a shell script that takes the current date on the server and stores it in a file. echo get /usr/home/data-`date '+%Y%d'`.xml> /usr/local/sandeep/GetFILE.ini I call this GetFILE.ini file from an sftp program to fetch a file from /usr/home/ as location. The file is in... (3 Replies)
Discussion started by: bsandeep_80
3 Replies

10. Programming

date issue

hi all: I want to create a new file dynamically for each day.how can i do this. eg.. struct tm tm; while(1) { if(tm.tm_hr==0 && tm.tm_min=0 && tm.tm_sec==0) { //create a new file.. ... (3 Replies)
Discussion started by: bankpro
3 Replies
Login or Register to Ask a Question