Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return list of triplicates

To find duplicates you can use

sort | uniq -d

but is there a quick way to find triplicates?

like image 740
D W Avatar asked Jan 21 '23 04:01

D W


1 Answers

You can use:

sort | uniq -c | awk '$1 == 3'

uniq -c gives you a count of occurences in the first column. The awk line filters all lines with has 3 in the first column.

If you want all items occuring 3 or more times write $1 >= 3

You can also pick out just the items names with (if they are just one column with no spaces) with:

sort | uniq -c | awk '$1 >= 3 {print $2}'

Ans so on ...

like image 165
Peer Stritzinger Avatar answered Feb 04 '23 20:02

Peer Stritzinger