从txt文件中收集特定行

时间:2017-12-19 08:03:28

标签: python matlab wolfram-mathematica

sample of the txt file

我想从包含 NVSS 关键字的txt文件中提取整行,并将其导出为新的txt文件,但我不知道如何执行此操作。 谢谢

1 个答案:

答案 0 :(得分:0)

提取包含' NVSS'的每一行。到一个新文件:

with open('infile.txt', 'r') as infile, open('outfile.txt', 'w') as outfile:
    for line in infile:
        if 'NVSS' in line:
            outfile.write(line)