Connecting Tech Pros Worldwide Help | Site Map

log files

  #1  
Old October 7th, 2008, 11:18 PM
Newbie
 
Join Date: Oct 2008
Posts: 5
I have this code here
import string
def count_and_sort():
filer = {}
f = open("loggfil.txt","r")
f2 = open("lab5.out","w")
person = "lisa.sm.luth.se"
while True:
rad = f.readline()
split = string.split(rad)
if rad == "":
f.close()
break
elif person in rad:
split2 = split[6]
filer[split2] = filer.get(split2,0) + 1
keys = filer.keys()
keys.sort()
for lines in keys:
f2.write(lines+"\n")
f.close()

this code prints out this from a log file
//csee/csn/include/div.cfg
/csee/csn//include/address.html
/csee/csn//include/footmenu.html
/csee/csn//include/links.html
/csee/csn/presentation.html
/csee/csn/research.html

I want it to display on the side of the filename how many times you downloaded it. I put everything in a dictionary but i can only get the keys. How do i get the values. Thanks in advance
  #2  
Old October 8th, 2008, 03:52 AM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,545

re: log files


Quote:
Originally Posted by cooolsson
I have this code here
Expand|Select|Wrap|Line Numbers
  1. import string
  2. def count_and_sort():
  3.     filer = {}
  4.     f = open("loggfil.txt","r")
  5.     f2 = open("lab5.out","w")
  6.     person = "lisa.sm.luth.se"
  7.     while True:
  8.             rad = f.readline()
  9.             split = string.split(rad)
  10.             if rad == "":
  11.                 f.close()
  12.                 break
  13.             elif person in rad:
  14.                 split2 = split[6]
  15.                 filer[split2] = filer.get(split2,0) + 1
  16.     keys = filer.keys()
  17.     keys.sort()
  18.     for lines in keys:
  19.         f2.write(lines+"\n")
  20.     f.close()
this code prints out this from a log file
//csee/csn/include/div.cfg
/csee/csn//include/address.html
/csee/csn//include/footmenu.html
/csee/csn//include/links.html
/csee/csn/presentation.html
/csee/csn/research.html

I want it to display on the side of the filename how many times you downloaded it. I put everything in a dictionary but i can only get the keys. How do i get the values. Thanks in advance
Please use code tags around your code!

To write the file name and quantity:
Expand|Select|Wrap|Line Numbers
  1. f2.write("\n".join(["%s %s" % (key, filer[key]) for key in keys]))
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically iterating through log files bay_dar@yahoo.com answers 1 November 17th, 2006 05:45 AM
Please evaluate this approach to shrinking log files William answers 2 September 8th, 2006 08:15 PM
reduce size of log files? Sue answers 2 November 12th, 2005 10:06 AM
how UDB reuse the Secondary Log Files hank answers 7 November 12th, 2005 06:29 AM
Moving log files buster answers 3 July 23rd, 2005 09:08 AM