00001 #!c:/python26/python.exe 00002 # 00003 # Simulate standard grep function. 00004 # 00005 # syntax: sqs0.py string_to_locate fileid 00006 # 00007 import sys #sys module for argv 00008 00009 search,fileid=sys.argv[1:3] #get the two words passed in parameter 00010 00011 try: 00012 id=open(fileid) #Open the file 00013 for l in id.readlines(): #loop on lines 00014 if l.find(search)>-1: #if locate string, 00015 print l[:-1] # then print the line 00016 except Exception,e: 00017 print e 00018 else: 00019 id.close() 00020