Question: Regex search within filesSkills and elements usedFile manipulation, input validation, regular expressionsProgram specificationWrite a program that takes the name of a text file and a
Regex search within filesSkills and elements usedFile manipulation, input validation, regular expressionsProgram specificationWrite a program that takes the name of a text file and a regular expression from the command line anddisplays any lines from the text file that match the regular expression along with the line number. Afteryour program is finished be sure and close your open file.Note: You will probably need to put quotes around your regular expression if it contains specialcharacters such as backslashes.Verify that the user has passed in the proper arguments and display an error if they have not.If the file does not exist or cannot be opened display an error.Example$ python search.pyError: You must supply a filename and regexEx. python search.py file.txt btestb$ python search.py file.txt btestb: The subject took the test and score an : since the test turned out to be meant forNote: and are the line numbers where the text appears within file.txt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
