Re: bash history customizing

From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 05/28/04


Date: Fri, 28 May 2004 07:41:37 -0500


Gabkin wrote:
<snip>
> I also want to eliminate all duplicate commands in my history file,
> but I want to keep the most recent duplicate only.
> In other words if my history contains this...
>
> 1 cd $HOME
> 2 vi somefile.txt
> 3 cp somefile anotherfile
> 4 exit
> 5 cd $HOME
> 6 vi somefile
> 7 exit
>
> I would like it to become
>
> 1 cp somefile anotherfile
> 2 cd $HOME
> 3 vi somefile
> 4 exit

Unless you get a better suggestion that doesn't involve a script, this
will do it:

tac file | awk '$1 in cmds{next}{cmds[$1]="";print}' | tac

Regards,

        Ed.