I am trying to grep through a file using os.system("grep 'regex' /path/to/file.log"). I know the regex is correct, and the command works when run from the shell, but once I try running the script I get the following error:
sh: /path/to/file.log: Permission denied
Is the os module not running with my permissions? Also, is there a better way to do this? I need to find specific lines in a 40,000+ line file.
THANKS!
It’s probably easier to do this using Python’s built in regex module,
re, rather than shelling out togrep.I know this doesn’t answer the question directly but it’s probably the right solution to the underlying problem. I think this falls into the “is there a better way to do this?” part of your question.