Tuesday, December 12, 2006

Sorting IPs in bash scripting

Oh yeah..This is something I had my head banging for a few minutes, till I figured out the -t option of sort. Okay..I had a list of IPs around 20000 today, for which I had to sort to find any patterns so that I can block the subnet in the firewall itself. I ended up with

sort -u -n -t. -k 1,1 -k 2,2 -k 3,3 -k 4,4 /etc/eximblacks

-k and -t were the key options you need to look in the menu. There are more than one way to do it :-).

That helped me. Hope it may help you at some point of time.

No comments: