Score:0

Uniq --count doesn't work properly

lk flag

I'm trying to solve a problem with counting IPs using uniq -c.

My file after using file looks like this :

69.246.75.77
7.44.104.171
195.82.180.9
195.82.180.9
61.115.160.23
56.240.142.58
195.82.180.9
87.22.27.189
56.240.142.58
211.114.204.171
204.55.182.16
242.113.24.81
196.34.105.115
28.74.152.20
161.130.133.151
8.89.127.206
175.173.236.111

But after using uniq -c I got a result:

  1 69.246.75.77
  1 7.44.104.171
  2 195.82.180.9
  1 61.115.160.23
  1 56.240.142.58
  1 195.82.180.9
  1 87.22.27.189
  1 56.240.142.58
  1 211.114.204.171
  1 204.55.182.16
  1 242.113.24.81
  1 196.34.105.115
  1 28.74.152.20
  1 161.130.133.151
  1 8.89.127.206
  1 175.173.236.111

So looking at for example 195.82.180.9 I got it 2 times, first with 2 and second with 1 number of occurences. Why doesn't it work as expected?

Thank you for your time.

Score:4
id flag

Uniq will only detect identical entries if they are adjacent (ie consecutive lines) - so you will need to sort the data before running uniq to get the true number of occurrences.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.