Created
August 20, 2012 10:02
-
-
Save kimmel/3402778 to your computer and use it in GitHub Desktop.
clean_history.pl without the patterns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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