300-215 · Question #98
Which scripts will search a log file for the IP address of 192.168.100.100 and create an output file named parsed_host.log while printing results to the console? A. B. C. D.
The correct answer is D. import os import re line_regex = re.compile(r".*fwd=\192\\.168\\.100\\.100\\W.*$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file.write("") with open("test_log_log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line with open("parsed_host.log", "a") as out_file: out_file.write(line). Option D is correct because it properly creates 'parsed_host.log' as the output file (matching the required filename), reads from the log file ('test_log_log') in read mode, prints each matching line to the console, and appends matching lines to 'parsed_host.log'. The script…
Question
Which scripts will search a log file for the IP address of 192.168.100.100 and create an output file named parsed_host.log while printing results to the console? A. B. C. D.
Exhibits
Options
- Aimport os import re line_regex = re.compile(r".fwd=\192\.168\.100\.100\W.$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file_write("") with open("output/filename_","a") as out_file: with open("parsed_host.log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line out_file.write(line)
- Bimport os import re line_regex = re.compile(r".fwd=\192\.168\.100\.100\W.$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file.write("") with open("test_log_log", "a") as out_file: with open("parsed_host_log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line out_file.write(line)
- Cimport os import re line_regex = re.compile(r".fwd=\192\.168\.100\.100\W.$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file.write("") with open("parsed_host.log", "a") as out_file: with open("test_log_log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line out_file.write(line)
- Dimport os import re line_regex = re.compile(r".fwd=\192\.168\.100\.100\W.$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file.write("") with open("test_log_log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line with open("parsed_host.log", "a") as out_file: out_file.write(line)
How the community answered
(29 responses)- A3% (1)
- B7% (2)
- C3% (1)
- D86% (25)
Explanation
Option D is correct because it properly creates 'parsed_host.log' as the output file (matching the required filename), reads from the log file ('test_log_log') in read mode, prints each matching line to the console, and appends matching lines to 'parsed_host.log'. The script correctly initializes the output file with an empty write, then reopens it in append mode inside the loop to capture results while simultaneously printing to the console.
Topics
Community Discussion
No community discussion yet for this question.



