in reply to How do I sort a file with IP Addresses and another text column?

print map{sprintf(("%d.%d.%d.%d,"x2)."%s\n",(split/,/)[1..8,0])} sort map{sprintf"%s".",%3d"x8,(split/\W/)[8,0..7]} <DATA> __DATA__ 1.2.3.4,1.2.3.255,USA 2.3.4.0,2.3.4.25,USA 124.2.3.0,124.2.3.255,Argentina
  • Comment on Re: How do I sort a file with IP Addresses and another text column
  • Download Code

Replies are listed 'Best First'.
Re: Answer: How do I sort a file with IP Addresses and another text column
by Saint Aardvark (Acolyte) on Jan 25, 2002 at 04:18 UTC
    I'd just like to add to this excellent answer...If you've just got a list of IP addresses to sort -- not two IP addresses plus a country -- here's how you'd do it:

    print map{sprintf(("%d.%d.%d.%d")."%s\n",(split/,/)\[0..3\])} sort map{sprintf"%3d,"x4,(split/\W/)\[0..3\]}

    It took a lot of scratching my head to adapt this, so I thought I'd save the next person the trouble. Hope it's useful!