0

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.

1 Answer 1

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.