B
Brian & Colleen
I'm using Active State Perl on a WinXP machine. I also run Cygwin and I
decided I wanted a utility to clean my .bash_history file to remove some
commands and duplicate lines.
The line endings are driving me nuts because I think Perl assumes it's on a
Win Platform but bash is writing Unix-style line endings. I keep ending up
with spurious ^M's in my .bash_history. I'm trying to force things with $/
and $\ but it isn't working. As you can tell from the code, I'm new to Perl
so it's probably something really simple.
----------------------------
use strict;
$/ = "\012"; # force use of Unix-style line endings as created
$\ = "\012"; # bash. Strip them on input and restore on output.
my $delstr = qr /exit|cd|ls|rm|cat|pwd|which/ ;
my $oldline = "zzzzzzz";
my $line = "";
open(INFILE,"<.bash_history");
open(OUTFILE,">.bash_history2");
while ($line=<INFILE>){
chomp $line;
if (($line !~ /$delstr/) && ($line ne $oldline)){
print OUTFILE "$line";
$oldline = $line;
}
}
close INFILE;
close OUTFILE;
if (rename ".bash_history2",".bash_history") {
print "Done.";
}
decided I wanted a utility to clean my .bash_history file to remove some
commands and duplicate lines.
The line endings are driving me nuts because I think Perl assumes it's on a
Win Platform but bash is writing Unix-style line endings. I keep ending up
with spurious ^M's in my .bash_history. I'm trying to force things with $/
and $\ but it isn't working. As you can tell from the code, I'm new to Perl
so it's probably something really simple.
----------------------------
use strict;
$/ = "\012"; # force use of Unix-style line endings as created
$\ = "\012"; # bash. Strip them on input and restore on output.
my $delstr = qr /exit|cd|ls|rm|cat|pwd|which/ ;
my $oldline = "zzzzzzz";
my $line = "";
open(INFILE,"<.bash_history");
open(OUTFILE,">.bash_history2");
while ($line=<INFILE>){
chomp $line;
if (($line !~ /$delstr/) && ($line ne $oldline)){
print OUTFILE "$line";
$oldline = $line;
}
}
close INFILE;
close OUTFILE;
if (rename ".bash_history2",".bash_history") {
print "Done.";
}