I need a way of searching a file using grep via a regular expression 'RE' from the unix command line. For example when i type in the command line:
python pythonfile.py 'RE' 'file-to-be-searched'
I need the regualr expression 'RE' to be searched in the file and print out the lines that contain the RE.
Ok so heres the coding i have:
import re
import sys
search_term = sys.argv[1]
f = sys.argv[2]
for line in open(f, 'r'):
if re.search(search_term, line):
print line,
if line == None:
print 'no matches found'
But when i enter a word which isnt present 'no matches found' doesnt print