Thursday, 12 September 2013

file filetering in python

import re
import os
import time

def sam(m):
    f1=open("%s" %m, "r")
    for i in f1.readlines():
        if "sam" in i:
            if m:
                return m



l=os.popen("ls -l")
for i in l.readlines():
    if "-r" in i:
        d=re.sub(' +',' ', i)
        w=d.split(" ")[8].strip()
        time.sleep(1)
        j=sam(w)
        if j is not None:
                       print j

No comments:

Post a Comment