Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Deleting lines prior to a date!

by SamCG (Hermit)
on May 09, 2006 at 17:05 UTC ( #548272=note: print w/replies, xml ) Need Help??


in reply to Deleting lines prior to a date!

I think you need something more like:
#! perl -w use strict; use Date::Calc qw(Delta_Days); my $outfile = 'new_logfile.txt'; my ($yr, $mo, $day) = qw/2006 1 1/; open OUT, ">", $outfile or die "Cannot open $outfile:$!\n"; while (<DATA>) { my ($line_year, $line_mon, $line_day) = /(\d{4})-(\d{1,2})-(\d{1,2}) +/; ## you need the date, unless you can rely on ordered dates. ## Your sample suggests they're unordered, so I'm going with that. ## if they're ordered, there are easier ways to do this my $delta_days = Delta_Days($line_year,$line_mon,$line_day,$yr,$mo,$ +day); print $delta_days; next if $delta_days > 0; print OUT $_; } close OUT; __DATA__ TICKETHELP###,########,1234567###,2004,X,Y,35.00###,2004-5-2 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,1234567###,2005,X,Y,16.00###,2005-3-8 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,1234567###,2006,X,Y,23.00###,2006-1-3 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,0933456###,2005,X,Y,33.00###,2005-5-7 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,1234567###,2005,X,Y,87.00###,2005-5-4 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,1984567###,2005,X,Y,32.00###,2005-3-8 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,1234567###,2005,X,Y,67.00###,2006-5-2 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,1223698###,2000,X,Y,79.00###,2000-1-1 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,1299n67###,2001,X,Y,26.00###,2001-5-5 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck
produces:
TICKETHELP###,########,1234567###,2006,X,Y,23.00###,2006-1-3 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck TICKETHELP###,########,1234567###,2005,X,Y,67.00###,2006-5-2 17:44:44, +TICKETHELP###########1234567###2005XY356.00###,World Cup List,John Ma +rck
from your data. You could also modify this to do other things like pick a specific date in the past or accept an argument as a date. I'd also suggest you look into zipping your files (it's not hard to do with perl, and can save a lot of space).



-----------------
s''limp';@p=split '!','n!h!p!';s,m,s,;$s=y;$c=slice @p1;so brutally;d;$n=reverse;$c=$s**$#p;print(''.$c^chop($n))while($c/=$#p)>=1;

Replies are listed 'Best First'.
Re^2: Deleting lines prior to a date!
by Anonymous Monk on May 09, 2006 at 18:15 UTC
    Thanks I am looking into that!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://548272]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2022-01-19 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?