Unix - count unique IP addresses, sort them by most frequent and also sort them by IP when number of repetitions is same

If your sort can do a stable sort, e.g. GNU sort with the -s or --stable option, lines with fields unrelated to the sort keys will not be sorted by those fields when there are ties, but will stay in their same relative positions.

$ sort -n -t. -k1,1 -k2,2 -k3,3 -k4,4 | uniq -c | sort -n -r -s
  5 72.204.55.250
  2 96.41.51.202
  2 141.8.143.179
  2 178.137.94.166
  2 208.115.113.91

Tags:

Bash

Uniq

Sort