in reply to grep for last 45 days

Well, looking at the code you've provided showing what you've tried so far . . .

Oh, you didn't. Never mind.

Read the line. Extract the timestamp. Parse the timestamp (see Date::Manip, Date::Calc). Compare with now. Print if it's within your window.

Update:

require 'time' now=Time.now ARGF.each do |line| next unless line =~ /(.*?) : Depth/ d_days = ( now - Time.parse( $1 ) ) / 86400 puts line if d_days < 45 end

Replies are listed 'Best First'.
Re^2: grep for last 45 days
by crashtest (Curate) on Mar 13, 2005 at 05:17 UTC
    The code worked for me. The only trick, it would appear, is to first run ln -s /usr/bin/ruby /usr/bin/perl.

    I was initially inclined to downvote the node for the horrible blasphemy of posting non-Perl code in the Monastary. Then I saw in my mind's eye the OP pasting the code into a file and trying to run it... what the... missing semicolon? I thought these guys knew their stuff!.

    So ++Fletch. I have Programming Ruby sitting on my bedside table, but have only browsed it so far. Ruby appears to be popular in Asia, and I really enjoyed some dabbling I've done in Smalltalk, so it might be right up my alley.

      Blasphemy for not using perl? Remember: TMTOWTDI, and some of the W's don't even involve perl . . . :)

      But yes that's kind of the point of using Ruby, especially if it's got a whiff of that homework smell about it (as this did) or if they've not shown any attempt at making an effort (again, as this did). Much of Ruby's close enough to Perl conceptually that you can (almost) see the equivalent Perl if you squint hard enough. Not to mention it gives an excellent chance for me to practice my Ruby.

Re^2: grep for last 45 days
by Anonymous Monk on Mar 14, 2005 at 03:04 UTC
    graff/fletch/tedpride/, Thank you very much The CODE WORKS!!!! Regards Greatfull
Re^2: grep for last 45 days
by Anonymous Monk on Mar 13, 2005 at 00:39 UTC
    Hi Fletch/TedPride, Thank you for the update ..BUT I am not sure if this gets all the records for the last 45 days. I did try the code you pasted...but its not showing all the records for the last 45 days Is there any other way of doing this in either perl or unix.