Question: Python help.. I need help Identifying if a certain keyword is in a python textfile, and then proceeding to extrat certain information from that file

Python help.. I need help Identifying if a certain keyword is in a python textfile, and then proceeding to extrat certain information from that file depending on the keyword. Refer below to code that i already have that is working. I need to know specifically how to extract a text file from a textfile inside of one.. for example a user inputs a text with the following

Given a file named "filewordcmd" with: """ FILEWORD filelabel "words" """

"words" in that text file is considered another text file with the following words in it, and i need to print out what is on the "words" text file: Given a file named "filewordcmd" with: """ FILEWORD filelabel "words" """

Usage: ./filemaker INPUTCOMMANDFILE OUTPUTFILE RECORDCOUNT

***** The following is the input from the user and the expected output.. please comment if you need me to clarrify

Scenario: Script supports the FILEWORD command Given a file named "filewordcmd" with: """ FILEWORD filelabel "words" """ Given a file named "words" with: """ one two three four five """ When I run `../bin/filemaker filewordcmd filewordoutput 1` Then the file "filewordoutput" should match /one|two|three|four|five/

************************************************************************************** HERE IS MY CURRENT CODE TO HELP YOU UNDERSTAND WHAT IM TALKIN ABOUT

import sys import re # read command line arguments inpFile = "in.txt" outFile = "out.txt" out2 = "out2.txt" out4 = "out4.txt" count = 1 # Open output file in write mode out = open(outFile,'w') out2 = open(out2,'w') with open(inpFile) as f: # for each line  for line in f: # if there is word STRING in line  if "HEADER" in line: # Writing to out file # multiplying by count for printing multiple times  out.write(str(re.findall(r'"(.*?)"', line, re.DOTALL)[0]).decode('string_escape')) if "STRING" in line: # Writing to out file # multiplying by count for printing multiple times  out.write(str(re.findall(r'"(.*?)"', line, re.DOTALL)[0]).decode('string_escape') * count) if "FILEWORD" in line: # Writing to out file # multiplying by count for printing multiple times  out2.write(str(re.findall(r'"(.*?)"', line, re.DOTALL)[0]).decode('string_escape')) #THIS IS WHERE I NEED HELP IN THE CODING TO ACCESS THAT TEXT FILE WITHIN THE TEXT FILE AND THEN PRINT THAT THOSE WORDS TO OUT  out.close() 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!