0

输入:- http://pastie.org/8355242

我正在尝试在给定的输入文件“input.txt”(如上面的粘贴链接中所示)中创建一个“.txt”文件,其中所有行都带有“wcnss_proc\bt”(作为参数传递)和“警告”。 ..在我开始python编码之前,我需要一个关于如何做到这一点的算法..任何人都可以提供输入吗?

4

2 回答 2

1
def filter_log(input_file, output_file, strs):
    with open(input_file, "r") as input, open(output_file, "w") as output:
        output.writelines(filter(lambda x: any([s in x for s in strs]), input.readlines()))

# here is just searched for "Warning", add other stuff
filter_log("input.txt", "output.txt", ["Warning"])
于 2013-09-25T19:24:36.817 回答
0

您需要查找sys.argv值来构建your_string

#pseudocode

good_lines = []
for line in open(filepath):
    if "your_string" in line:
      good_lines.append(line)

with open(new_file, 'w') as f:
  for line in good_lines:
      f.writeline(line)
于 2013-09-25T19:05:56.577 回答