Skip to content

Instantly share code, notes, and snippets.

@cornfeedhobo
Last active May 5, 2022 01:15
Show Gist options
  • Save cornfeedhobo/ba1a271f2b30f7bfc3100a5ad33be300 to your computer and use it in GitHub Desktop.
Save cornfeedhobo/ba1a271f2b30f7bfc3100a5ad33be300 to your computer and use it in GitHub Desktop.
Sort bash history files with timestamps
#!/bin/sh
# Example usage:
# cat hosts/*/.bash_history | sort-timestamp-history > merged_history
exec \
sed \
-e '/^$/d' \
-e '/^#/N' \
-e '/^#/!s/^/#0\n/' \
-e 's/#//' \
-e 'y/\n/ /' \
- |
sort -uk2 |
sort -n |
sed -e 's/\(\S\+\) /#\1\n/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment