I'm developing a command line tool that searches for certain string (hex, ascii, PAN etc...) data in log files. I have a few lines written that uses a regular expression to filter the search. Ideally, I want to be able to visually see all .txt and .log files in the current directory, have them enumerated, so I can choose a number to select a file to search through for a particular string (filtered by re). Any help is appreciated. Here's what I have so开发者_如何学Go far:
logfile = open("file.txt", "r")
regex = re.compile(r'3[1-9]\d{10}') #re search for a 12 digit string that starts with 3,
#and whos second number is 0-9.
for line in logfile:
search_string = regex.findall(line)
for word in search_string:
print word
I can't answer the entire question, but if you're looking to do some sort of interactive shell based operations, the cmd module from the standard library is a good starting point.
精彩评论