Searching between dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching between dates
# 1  
Old 08-20-2005
Searching between dates

Hello people,
I have a file containing dated entries. Is there a way to search between dates? for example, in a file <file.text> with entries

04-jul-2005 login: pty0 xxxxxx xxxxxx
09-jul-2005 logout pty34 xxxxxx xxxxxx
11-aug-2005 arp port17 xxxxxx xxxxxx
30-sep-2005 awk line14 xxxxxx xxxxxx



In that format.

I want to search between july 9 and sep 30.

I have tried all tricks, no dice (so far). Any assistance will be appreciated
# 2  
Old 08-20-2005
ruby -nle 'puts $_ if Time.local(*$_.split(/-| .*/).reverse).between?(Time.local(5,7,9),Time.local(5,9,30))'
# 3  
Old 08-21-2005
It gives a syntax error.
# 4  
Old 08-21-2005
touch -t 200507090000.00 tempStartDateFile
touch -t 200509302359.59 tempEndDateFile

find $directory -name * -newer tempStartDateFile ! -newer tempEndDateFile
# 5  
Old 08-22-2005
That last solution assumes that I am searching for files within a directory. Actually, what I am doing is searching between different entries within a single file.

Last edited by Khoomfire; 08-22-2005 at 05:04 AM..
# 6  
Old 08-22-2005
Lots of ways to do it, easy if you have the Date::Manip perl module, but without you could put the following code in a file (make it executable). and run it with the input text file as the argument.

Assumes all lines are of the format in your original post and there are no leading spaces on the lines.

Code:
#!/usr/bin/perl
%months = (
  jul => 7,
  aug => 8,
  sep => 9
);

while (<>)
{
  @a = split('-');

  if ( $months{$a[1]} == 8 ||
       ($months{$a[1]} == 7 && $a[0] >= 9) ||
       ($months{$a[1]} == 9 && $a[0] <= 30)
     )
  {
    print;
  }
}

# 7  
Old 08-22-2005
Umm... actually, I have entries from January to december, and dating since 2003. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display dates between two dates

Hi All, I have 2 dates in mm/dd format. sdate=10/01 (October 01) edate=10/10 (October 10) I need the dates in between these 2 dates like below. 10/01 10/02 10/03 10/04 10/05 10/06 10/07 10/08 (1 Reply)
Discussion started by: jayadanabalan
1 Replies

2. Shell Programming and Scripting

Help searching for dates - Oracle ALERT log

Hi, I am searching for some specific string in an Oracle DB alert log and then possibly print the latest date string that I can find that the error happen. I can't work out how to search for date strings more so searching in some specific direction, i.e backward or forward. At the moment,... (1 Reply)
Discussion started by: newbie_01
1 Replies

3. UNIX for Advanced & Expert Users

How to get the Missing dates between two dates in the table?

Hi Am Using Unix Ksh ... I have a Table called date select * from date ; Date 01/02/2013 06/02/2013 I need the output as Missing Date 01/02/2013 02/02/2013 03/02/2013 04/02/2013 05/02/2013 06/02/2013 (2 Replies)
Discussion started by: Venkatesh1
2 Replies

4. Shell Programming and Scripting

Generating dates between two dates

HI, i have row like this HHH100037440313438961000201001012012073110220002 N in this i have 2 dates in pos 25-32 and 33-40 , so based upon the se two dates , i need to generated records between these two values so in the above record 20100101 and 20120731 need to genearte rows like this... (4 Replies)
Discussion started by: sathishsr
4 Replies

5. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

6. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

7. Emergency UNIX and Linux Support

Replacing dates]] with (dates)]]

Hi guys, For my wiki site I need to fix 1400 pages that use the wrong date format, most pages (not all) use eg. 1988]] I need to change that to (1988)]] The date range goes back to 1400 so I guess I need to do the following ssh into my server, dump mysql database vi .sql dump search... (20 Replies)
Discussion started by: lawstudent
20 Replies

8. Programming

SQL: find if a set od dates falls in another set of dates

Don't know if it is important: Debian Linux / MySQL 5.1 I have a table: media_id int(8) group_id int(8) type_id int(8) expiration date start date cust_id int(8) num_runs int(8) preferred_time int(8) edit_date timestamp ON UPDATE CURRENT_TIMESTAMP id... (0 Replies)
Discussion started by: vertical98
0 Replies

9. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. Shell Programming and Scripting

help searching log file with dates

Im tyring to create a script that will show me any lines in a file with todays date and yesterdays, the date format in the file is as follows ----- amqxfdcx.c : 728 -------------------------------------------------------- 07/12/05 09:53:20 AMQ6109: An internal WebSphere MQ error has... (3 Replies)
Discussion started by: csaunders
3 Replies
Login or Register to Ask a Question