Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import cgi
- import re
- form = cgi.FieldStorage()
- searchParam = form.getvalue('searchString')
- print('Content-type:text/html\n')
- print('<!DOCTYPE html>')
- print('<html><body>')
- print('<p>',searchParam,'</p>\n<hr>')
- with open('test2_animals_1.txt') as f:
- fileData = f.readlines()
- for index, line in enumerate(fileData):
- print('<p>Line ', index+1, ' - ', line, '</p>')
- print('<p>Total number of lines in the file = ', len(fileData), '</p>\n<hr>')
- matchedLines = 0
- unmatchedLines = 0
- print("<h1>Lines that don't contain '", searchParam, "'</h1>")
- for line in fileData:
- if(re.search(searchParam, line) == None):
- unmatchedLines+=1
- print("<p>", line, '</p>')
- else:
- matchedLines+=1
- print('<p>Lines matching input string: ', matchedLines, '</p>')
- print('<p>Lines not matching input string: ', unmatchedLines, '</p>')
- print('</body></html>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement