#! /usr/bin/env perl use warnings; use strict; # for each filename on the command line # get the modtime # make a backup of the file # - error if there is already a backup? # flush the live version(?) # start a line-by-line copy of the backup to the new file, # doing the BeginDate/EndDate substitution # 3-oct-11 18:20 # 01-Aug-2011 17:56 # without the 'm' no minutes are included. my $i; my $mod_time; my $stamp; my @m_abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); foreach ( @ARGV ) { $i = $_; $mod_time = (stat ($i))[9]; $stamp = localtime($mod_time); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mod_time); $year += 1900; # print "<$i> at <$stamp>\n"; open(my $IFILE, "<", $i) or die "Cannot open < $i: $!"; open(my $OFILE, ">", $i.".new") or die "Cannot open > $i.new: $!"; while(<$IFILE>) { if (/(.*).*(.*)/) { # print "Got: $_"; # print "as: <$1><$2><$3>...<$4>\n"; print { $OFILE } $1,$2,$3; printf { $OFILE } "%s-%s-%s %02d:%02d", $mday,$m_abbr[$mon],$year,$hour,$min; print { $OFILE } $4,"\n"; } else { print { $OFILE } $_; } } close($IFILE); close($OFILE); # utime(time, $mod_time, "$i.new") || die "touch $i.new failed: $!"; # rename $i,"$i.old" || die "rename $i,$i.old failed: $!"; rename "$i.new",$i || die "rename $i.new,$i failed: $!"; }