Return list of three instances

To find duplicates you can use

sort | uniq -d 

but is there a quick way to find triples?

+4
source share
1 answer

You can use:

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

uniq -c gives you the number of occurrences in the first column. Row awk filters all rows with 3 in the first column.

If you want all elements having 3 or more times write $1 >= 3

You can also select only the names of the elements with (if they are just one column without spaces):

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

Ans so on ...

+9
source

All Articles