I have a variable called ip that contains a list of IPs.
$ echo $ip
218.25.208.92 218.25.208.92 53.170.26.175
8.135.72.164 244.105.203.71 211.118.89.4
100.29.91.148 187.225.13.147 48.204.157.1452 182.237.138.26 182.237.138.26 182.237.138.26
211.118.89.4 100.29.91.148 100.29.91.148
I am trying to iterate over this string and find the IPs which are repeated more than 2 times. If the IP is repeated more than two times, show the amount of times the IP is found.
I thought this could be managed with a for loop, but I am quite lost.
I tried using grep -o. It shows how many times that IP appears, but I have to specify each IP manually...
echo $ip | grep -o 218.25.208.92 | wc -l
Newer code:
for i in $ip; do
echo $ip | grep -o $i | wc -l
done
uniqcommand with the-cand-doptions.