Skip to content

Instantly share code, notes, and snippets.

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 walquis/deb4998f4107c6624e49323f9491d10a to your computer and use it in GitHub Desktop.
Save walquis/deb4998f4107c6624e49323f9491d10a to your computer and use it in GitHub Desktop.
Linux one-liner: Report top X instances of pattern Y in a file.
# For instance, which users had the most occurrences of their name in logfile auth.log?
$ date; grep --only-matching "member=[^ ]*" auth.log | sort | uniq --count | sort -rn| head -8
# grep -o, --only-matching -- Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
# uniq -c, --count -- Prefix lines by number of occurrences
# sort -rn, --reverse ... -n, --numeric-sort
Mon May 9 22:09:34 UTC 2016
223163 member=some-user
19665 member=another-user
16325 member=jfrancis
14569 member=wtell
12976 member=fed6dcff2245df50272763f9088df1e2ad7b5a09
12114 member=ybly
8354 member=aledsinger
7651 member=jrapp
admin@some-host:/var/log/some-system$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment