in reply to Extract data based on dates and place in new file
This takes advantage of the fact that dates in this format, YYYYMMDD, are naturally sortable and can be string compared for greater than, less than or equality.#!/usr/bin/perl use strict; use warnings; use Date::Simple qw/ today /; my $yesterday = today() - 1; my $wk_before = $yesterday - 7; for ($yesterday, $wk_before) { $_ = $_->strftime('%Y%m%d'); } while (<DATA>) { print if $_ ge $wk_before && $_ le $yesterday; } __DATA__ 20110801-23:42:01,4 20110802-23:42:01,4 20110802-23:45:01,3 20110802-23:48:01,1 20110802-23:51:01,1 20110802-23:54:01,2 20110802-23:57:01,3 20110803-00:00:01,3 20110810-23:42:01,4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extract data based on dates and place in new file
by Anonymous Monk on Aug 11, 2011 at 17:23 UTC | |
by dtbach (Novice) on Aug 16, 2011 at 17:30 UTC | |
by Anonymous Monk on Aug 17, 2011 at 02:39 UTC |