python grep reverse matching

Posted by thomytheyon on Stack Overflow See other posts from Stack Overflow or by thomytheyon
Published on 2010-05-26T04:43:48Z Indexed on 2010/05/26 4:51 UTC
Read the original article Hit count: 179

Filed under:
|
|

Hi Alls,

I would like to build a small python script that basicaly does the reverse of grep. I want to match the files in a directory/subdirectory that doesn't have a "searched_string".

So far i've done that:

import os

filefilter = ['java','.jsp'] 
path= "/home/patate/code/project"
for path, subdirs, files in os.walk(path):
    for name in files:
        if name[-4:] in filefilter :
        print os.path.join(path, name)

This small script will be listing everyfiles with "java" or "jsp" extension inside each subdirectory, and will output them full path.

I'm now wondering how to do the rest, for example i would like to be able if I forgot a session management entry in one file (allowing anyone a direct file access), to search for : "if (!user.hasPermission" and list the file which does not contain this string.

Any help would be greatly appreciated !

Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about grep