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...
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.
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
Desired output should be
Thus my query should be generic for all timings and not just for 23:59.
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
Desired output should be
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!
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)
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)
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)
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)
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)
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)
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)
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)