History list without timestamp and unique the results

Using bash, I save my history with the timestamp.

How do print the history omitting the timestamp?

alias h=history
alias g=grep -i

To find lines that I used for heroku, I type:

> h | g heroku

I'd like to unique the results without the time-stamp, naturally.

This question is somewhat related: How to avoid duplicate entries in .bash_history

However, sometimes I want to see the duplicate in the history to see the context under which a command was run.


Solution 1:

Simply, history | sed 's/.[ ]*.[0-9]*.[ ]*//' | uniq | grep -i "heroku"

the sed will remove the any [spaces][numbers][spaces] at the start of each line

for optimization make it

history | grep -i "heroku" | sed 's/.[ ]*.[0-9]*.[ ]*//' | uniq

Solution 2:

Addition to answer by @devav2

Clear/nullify the history timestamp environment variable

HISTTIMEFORMAT="";

Export the following command,

export HISTCONTROL=ignoredups --> This will ignore the duplicates that are executed in sequence