I am new to bash programming and I am struggling with arrays and how to operate with them. SCENARIO:
I have a variable called x which is composed of a group of IP's. This is the output when I echo $x from my script
182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 201.21.24.22 201.21.24.22 201.21.24.22
44.21.25.31 44.21.25.31 44.21.25.31 44.21.25.31
Then, I would like to know how many times each IP is repeated. The desired output would be:
15 182.100.67.59
4 44.21.25.31
3 201.21.24.22
I have tried the following
(IFS=" "; sort <<< "$x" ) | uniq -c
Output Note the first 1 on the output.
**1** 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 182.100.67.59 201.21.24.22 201.21.24.22 201.21.24.22 44.21.25.31 44.21.25.31 44.21.25.31 44.21.25.31
I am not seeing this, It should be pretty simple but I can't find the solution :( Thanks! And very great community!