If I have a list in bash
L="11 22 11 33 22 44"
Is there a clean way to get to "11 22 33 44" ?
Using tr, the numbers are split to individual lines, and sort is used to sort the numbers(-n) and remove the duplicate ones(-u).
A common pattern in some other programming languages is to store each value as a 'key' in a hash or dictionary or associative array, and rely on the implementation to keep hash keys unique.
Another one I've found useful for checking the list of unique IPs connecting to your servers, from the 'netstat' command is this:
Netstat Output Example
tcp 0 0 192.168.1.196:8009 192.168.21.124:45921 TIME_WAIT
In this example I'm starting by filtering the TCP port, cutting out the local information, sorting the list and then piping it to the 'uniq' command.
netstat -an | grep ":8009" | cut -d " " -f 28 | cut -d ":" -f 1 | sort -u
What I get is a list of the 2 unique foreign IP addresses connecting to my system.
If you did some fancy monitoring stuff, you can graph the total number of unique nodes connecting, compare the list to your white list of allowed IPs, add non-authorized IPs to your black list, etc.
Extending on Gurus answer above, if you have an array you can: