#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Search file for text and print the first four characters to the right.


    Hello,

    I am attempting to search log files and print the duration on each line that lists a duration.

    So, if the line looks like this:
    duration: 0.700

    It will print an int:
    0.7

    Here's what I have so far:

    Code:
    import glob
    import os
    os.chdir("/pglog/")
    for files in glob.glob("*.log"):
    	for line in open(files):
    		if ":  duration: " in line:
    			print files
    			print line # just print value beside "duration"
    Thanks in advance for any help.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,843
    Rep Power
    480
    Code:
    line.split(":  duration: ")[1][:4]
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo