sortuniq

command module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 9 Imported by: 0

README

sortuniq

Count the occurence of the lines. Basically sortuniq is equivalent to sort | uniq and sortuniq -cn is equivalent to sort | uniq -c | sort -nr.

$ sortuniq -h
Usage:
  sortuniq [OPTIONS]

Application Options:
  -c, --count    Prefix the number of occurrences
  -n, --order    Sort by the number of occurrences
  -r, --reverse  Reverse the order

Help Options:
  -h, --help     Show this help message


$ ps aux | awk '{print $1}' | sortuniq
USER
haccht
message+
root
syslog
systemd+
www-data

$ ps aux | awk '{print $1}' | sortuniq -cn
  99  root
  14  haccht
   3  systemd+
   2  www-data
   1  syslog
   1  message+
   1  USER

Performance comparison:

$ time ( cat /dev/urandom | tr -dc '0-9' | fold -w 5 | head -n 10000000 | sortuniq -cn > /dev/null )

real    0m2.516s
user    0m1.891s
sys     0m0.594s

$ time ( cat /dev/urandom | tr -dc '0-9' | fold -w 5 | head -n 10000000 | sort | uniq -c | sort -nr > /dev/null )

real    0m20.529s
user    0m16.484s
sys     0m1.125s

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL