poj#!/usr/bin/perl use strict; use warnings; my $start = ymd('01/02/2018'); my $end = ymd('06/02/2018'); my $infile = 'input.txt'; my $outfile = 'output.txt'; open IN, '<',$infile or die "Could not open '$infile' : $!"; open OUT, '>',$outfile or die "Could not open '$outfile' : $!"; my $count=0; while (<IN>){ if (/(\d{2}\/\d{2}\/\d{4})\s*$/){ my $date = ymd($1); if ($date >= $start && $date <= $end){ print OUT $_; ++$count; } else { print "$date Skipped : $_"; } } else { print "No date : $_"; } } close IN; close OUT; printf "%d records written to '%s'\n",$count, $outfile; sub ymd { sprintf "%04d%02d%02d",reverse split /\D/,shift; }
In reply to Re: extract lines from file between date range.
by poj
in thread extract lines from file between date range.
by rinkish85
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |