My history is 'polluted' with some specific lines that have typo's and such. For example: I often have to ssh to a certain server like so:
ssh foo-bar@domain.tld
> Connects succesfully
But I also make a typo sometimes:
ssh bar-foo@domain.tld
> Permission denied
Because I rely on history this typo is duplicated multiple times:
cat .zsh_history | grep bar-foo@domain.tld
> : 1510301683:0;ssh bar-foo@domain.tld
> : 1511166682:0;ssh bar-foo@domain.tld
> : 1511193552:0;ssh bar-foo@domain.tld
> : 1512730972:0;ssh bar-foo@domain.tld
> : 1516368993:0;ssh bar-foo@domain.tld
> : 1516802690:0;ssh bar-foo@domain.tld
> : 1519633368:0;ssh bar-foo@domain.tld
Is there an easy way to clean up my history purely by the results of the grep-command? (or perhaps there's some other, more clever solution?)
Update:
Please note: I am not looking for a way to delete line x from the history; I know there are plenty of articles out there that cover that. I'm simply looking for a (simple?) way to delete all lines that contain string y.
x. The linked question is how to delete by line numbers. – Giel Berkers Apr 24 '18 at 08:33grepfix is in a comment by *mivk, which prints out the needed commands, (without actually running them):history | grep XYZ | grep -v grep | tac | awk '{print "history -d", $1}'– agc Apr 25 '18 at 00:59