Re: bash history customizing

From: Thorsten Kampe (thorsten_at_thorstenkampe.de)
Date: 05/28/04


Date: Fri, 28 May 2004 15:25:21 +0200


* Gabkin (2004-05-28 14:12 +0100)
> On Fri, 28 May 2004 11:22:16 +0200, Thorsten Kampe
> <thorsten@thorstenkampe.de> wrote:
>
>>* Gabkin (2004-05-28 08:55 +0100)
>>> 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
>>>
>>> This way, over time most of my useful, regularly used commands would
>>> rise to the top, while the useless ones would sift to the bottom of
>>> the list. (for eventual manual purging?)
>>>
>>> The obvious way is via a sort -u, but this sorts alphabetically which
>>> is totally not what I want.
>
>>uniq or zsh
>
> uniq cant do anything that a sort -u cant do,

Think again: uniq has the ability /not to sort/ and "sort" hasn't got
this ability.

> unless there is some kind of uniq option to get rid of duplicates
> but keep the _last_ duplicate, not the first.

tac | uniq | tac

> Also, I dont want to sort the history alphabetically, Im trying to
> sort it by common usage.
>
> As for zsh, I'm a bash man!

So what? If you want basic functionality you use a basic tool suited
for that (bash). If you want extended functionality you use a tool
appropriate for that (zsh)

Thorsten



Relevant Pages

  • Re: Finding common lines between text files
    ... Yes, as someone else has said, uniq only removes consecutive duplicates, ... so it's necessary to have a sorted input in order to remove all duplicates. ... If your data isn't sorted, you could run sort before passing it to uniq, ... can do that with a Perl one-liner: ...
    (comp.unix.programmer)
  • Re: uniq without sort <-------------- GURU N
    ... I know it is very easy to find uniq or non-uniq lines if you scramble ... So it is TRIVIAL with sort. ... I want uniq without sorting the initial order. ...
    (comp.unix.shell)
  • Re: uniq without sort <-------------- GURU N
    ... I know it is very easy to find uniq or non-uniq lines if you scramble ... So it is TRIVIAL with sort. ... I want uniq without sorting the initial order. ...
    (comp.unix.shell)
  • Re: Help: Duplicate and Unique Lines Problem
    ... Dose perl has functions like the UNIX command sort and uniq can output ... want to save the duplicate line just once and unique line. ...
    (comp.lang.perl.misc)
  • Re: Sort uniq
    ... but I thought the %uniq would have the sort ... sort sorts, a hash unique-ifies. ... do you think you could do me a favor and NOT include this signature in ...
    (perl.beginners)