Regex Python Help
Gregg Dotoli
gdotoli at gmail.com
Tue Mar 24 15:43:38 EDT 2015
This works fine , but I have to pipe the filename to the script python stool <foo
All I need is a loop, should I bag Python and use a simple shell for loop?
import sys
import re
import os
pattern="DECRYPT_I"
regexp=re.compile(pattern)
for line in sys.stdin:
result=regexp.search(line)
if result:
sys.stdout.write(line)
On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote:
> I am creating a tool to search a filesystem for one simple string.
> I cannot get the syntax correct.
> Thank you in advance for your help.
>
> import sys
> import re
> import os
> path='/'
> viewfiles=os.listdir(path)
> for allfiles in viewfiles:
> file= os.path.join(path, allfiles)
> text=open(file, "r")
> for line in text:
> if re.match("DECRYPT_I", line):
> print line,
>
> ----------------------------------------------------------
> This should search every file for the simple regex "DECRYPT_I"
> This is from the root down.
>
> The error is:
>
> SyntaxError: Missing parentheses in call to 'print'
>
> Please help.
> Gregg Dotoli
More information about the Python-list
mailing list