开发者

Enumerating and displaying files in the current directory and selecting by number to search for the file via cmd line

开发者 https://www.devze.com 2023-02-25 09:39 出处:网络
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'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消