Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-20-2005
Registered User
 

Join Date: Aug 2005
Posts: 68
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
Sponsored Links
  #2 (permalink)  
Old 08-20-2005
Registered User
 

Join Date: Jul 2005
Posts: 137
ruby -nle 'puts $_ if Time.local(*$_.split(/-| .*/).reverse).between?(Time.local(5,7,9),Time.local(5,9,30))'
  #3 (permalink)  
Old 08-21-2005
Registered User
 

Join Date: Aug 2005
Posts: 68
It gives a syntax error.
  #4 (permalink)  
Old 08-21-2005
Registered User
 

Join Date: Jul 2005
Posts: 21
touch -t 200507090000.00 tempStartDateFile
touch -t 200509302359.59 tempEndDateFile

find $directory -name * -newer tempStartDateFile ! -newer tempEndDateFile
  #5 (permalink)  
Old 08-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 68
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 (permalink)  
Old 08-22-2005
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
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 (permalink)  
Old 08-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 68
Umm... actually, I have entries from January to december, and dating since 2003.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Time Between Dates Sreejith_VK Shell Programming and Scripting 3 02-20-2008 01:06 AM
help searching log file with dates csaunders Shell Programming and Scripting 3 08-23-2005 12:50 PM
comparing 2 dates k_oops9 Shell Programming and Scripting 7 11-15-2004 02:07 AM
match dates poohxiong UNIX for Dummies Questions & Answers 3 05-27-2003 03:03 PM
compare two dates wchen Shell Programming and Scripting 6 10-24-2002 05:39 PM



All times are GMT -4. The time now is 06:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0