<p>I love <strong>Python</strong> ... I couldn't resist writing you some code. It would be easy to generalize it to check all the files in a directory ... but I'm trying to hook you!</p>
<p>I am sure it could be done in a more Pythonic way, but python is great for string stuff -- way more readable than <strong>Perl</strong>. (<em>Flame war alert!</em>)</p>
<pre><code> #!/usr/bin/python
""" USAGE: python two_tags.py data.txt target1 target2
Scans for two arbitrary text strings
$ python two_tags.py data.txt gosh golly
Search 6 lines -- gosh NOT FOUND., golly FOUND!
python two_tags.py data.txt golly howdy
Search 2 lines -- golly FOUND!, howdy FOUND!
"""
#Sample file data.txt for testing code
#asdfs fsdf howdy a ha b
#safd golly gee
#whiz
#zard
#spam
#golly
import string
import sys
args=sys.argv
fn=args[1] #This contains the filename you passed on the command line
Input_file=fn
print args #For debug
target1=args[2]
target2=args[3]
f=open(Input_file,'r')
line_count=0
target1_found='NOT FOUND.'
target2_found='NOT FOUND.'
for line in f:
line_count+=1
x=string.find(line, target1)
if x>-1:
target1_found='FOUND!'
x=string.find(line, target2)
if x>-1:
target2_found='FOUND!'
if (target1_found=='FOUND!') and (target2_found=='FOUND!'):
break
f.close()
print("Search %i lines -- %s %s, %s %s\n" % (line_count, target1, target1_found, target2, target2_found))
</code></pre>