I have a text file that is listing ip's like below. The text file contains hundreds of entries like below. I need to seperate each entry in the text file and sort them in IP order. How would I go about doing that?

109.77.140.67 - - [30/Jun/2013:07:07:05 -0500] "GET /email/13948staticvoid.gif HTTP/1.1" 200 17181 "http://www.bereans.org/email/index.php" "Mozilla/5.0 (PLAYSTATION 3 4.41) AppleWebKit/531.22.8 (KHTML, like Gecko)"
79.169.182.242 - - [30/Jun/2013:07:07:05 -0500] "GET /email/index.php HTTP/1.1" 200 3501 "http://serw.clicksor.com/newServing/links.php?zone=8340&chad=1&adu=2&cs=&adtype=2&nid=1&sid=188811&pid=126179&spid=&image=2&memkey=fa8ec13fec1054c2f9881b1bdbef4f48&durl=&lq=0&lb=16&qp=YF4lJzX7JC0n-SE0eyEpIv35b1NXNH4gKDT-JHxhTy0xISkrJPsnMXsmJyF7Ii99Ky73XGM5_iYuIHwpMP0lJw" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"

I have tried sorting, but everytime it just sorts by individual letter and not by line

words=open("logbook.txt").read()
print=words

Any help is greatly appreciated.

Recommended Answers

All 2 Replies

Why you are redefining the print?

Have you tried .readlines() instead of .read() ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.