Skip to content

Instantly share code, notes, and snippets.

@kimmel
Created August 20, 2012 10:02
Show Gist options
  • Select an option

  • Save kimmel/3402778 to your computer and use it in GitHub Desktop.

Select an option

Save kimmel/3402778 to your computer and use it in GitHub Desktop.
clean_history.pl without the patterns
#!/usr/bin/perl
use 5.014;
use warnings;
use autodie;
use utf8::all;
use IO::All;
die 'No input file specified.' if ( $#ARGV == -1 );
my @patterns = map {qr/^$_/xms} @{
[ '(?:mk|rm)dir\ ',
'(?:acroread|epdfview)\ ',
# etc..
]
};
foreach my $fname (@ARGV) {
my @content = io($fname)->slurp;
foreach (@content) { s/^\s+//xms; s/[ ]+$//xms; }
open my $fh, '>', $fname . '_clean';
open my $junk, '>', $fname . '_junked.log';
LINE: foreach my $line (@content) {
foreach my $re (@patterns) {
if ( $line =~ $re ) {
print {$junk} $line;
next LINE;
}
}
print {$fh} $line;
}
close $fh;
close $junk;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment