Last active
May 10, 2016 15:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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