|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 |
|
|
|
|||
|
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;
}
}
|
|
|||
|
Umm... actually, I have entries from January to december, and dating since 2003.
![]() |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |