Skip to content

Instantly share code, notes, and snippets.

@uilian
Created October 18, 2022 18:46
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 uilian/04d4be0d1cc961ee2d17472a3b74f472 to your computer and use it in GitHub Desktop.
Save uilian/04d4be0d1cc961ee2d17472a3b74f472 to your computer and use it in GitHub Desktop.
Remove duplicates from zsh_history
# Remove duplicates from zsh_history:
$ cat -n .zsh_history | sort -t ';' -uk2 | sort -nk1 | cut -f2- > .zsh_no_duplicates_history
$ mv .zsh_no_duplicates_history .zsh_history
# In case of failure (i.e, `sort: Illegal byte sequence`), debug
# replacing the command above with `head`:
$ head -n 10000 .zsh_history | sort -t ';' -uk2 | sort -nk1 | cut -f2-
# Replace the number above in a binary search style until
# you find the culprit; then, remove the line and proceed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment