Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

Know what customers expect from the firm when they complain.

Answered: 1 week ago

Question

Understand why customers complain.

Answered: 1 week ago