Howdy :)

This is quite simple. Because your data is regular, you can use split to extract the date/time stamp from each record. Then you can use something like Date::Parse to convert the date/time stamp into a unix timestamp. After that, it's just a bit of simple arithmetic.

Here is some example code to demonstrate:

#!/usr/bin/perl -l use strict; use warnings; use Date::Parse; my $cutoff_date = time - (45 * 86400); while (my $line = <DATA>) { chomp($line); my $date = (split /\|/, $line)[15]; my $unixdate = str2time($date) or next; print "I would ", $unixdate < $cutoff_date ? "archive" : "not arch +ive", " $date"; } __DATA__ type|address|city|state|size|rent|term|company|contact|phone|email|web +site|ID|REMOTE_ADDR|HTTP_USER_AGENT|DATE|SORTORDER MFG|10 Oakmead Pkwy|San Jose|CA |10,000|$1.25|Net|Cushman Wakefield|To +m Cushman|408 555-8777|tom@cushman.com|http://www.google.com|1000000| +76.102.98.35|Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET +CLR 2.0.50727)|16:01:08 2007-01-10|1003 LAND|10 Oak|San Jose|CA|14,000|$1.25|Net|Ritchie Commercial|Don Ritchi +e|408 555-8777|tom@cushman.com|http://www.yahoo.com|1000001|76.102.98 +.35|Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.5 +0727)|16:28:03 2008-01-10|1002
Which prints:
I would archive 16:01:08 2007-01-10 I would not archive 16:28:03 2008-01-10

Hope this helps,
Darren :)


In reply to Re: Extracting Line from Text file over 45 days old by McDarren
in thread Extracting Line from Text file over 45 days old by chris654

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.