Skip to content

Instantly share code, notes, and snippets.

@perforb
Created January 26, 2013 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perforb/4642371 to your computer and use it in GitHub Desktop.
Save perforb/4642371 to your computer and use it in GitHub Desktop.
.(BASH|ZSH)_HISTORY CLEANER - Delete duplicate rows as keeping the order.
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
my @lines;
while (<>) {
chomp;
next unless $_;
push @lines, $_;
}
my %seen;
my @uniq = grep { ++$seen{$_} < 2 } @lines;
say $_ for @uniq;
__END__
=head1 NAME
.(BASH|ZSH)_HISTORY CLEANER
=head1 DESCRIPTION
Delete duplicate rows as keeping the order.
=head1 USAGE
cat ~/.zsh_history | perl history_cleaner.pl > ~/.zsh_history.tmp; mv ~/.zsh_history.tmp ~/.zsh_history
cat ~/.zsh_history | perl history_cleaner.pl > ~/.zsh_history.tmp; mv ~/.zsh_history.tmp ~/.zsh_history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment