【问题标题】:Collect Specific Rows from txt file [closed]从 txt 文件中收集特定行 [关闭]
【发布时间】:2017-12-19 08:03:27
【问题描述】:

sample of the txt file

我想从具有 NVSS 关键字的 txt 文件中提取整行并将其导出为新的 txt 文件,但我不知道该怎么做。 谢谢

【问题讨论】:

  • 如果您想得到任何答案,请详细说明您的问题。完全不清楚您在问什么,您尝试过什么(如果您尝试过)等
  • 你的问题应该表现出某种努力。你尝试过什么吗?如果是,请分享。
  • 如果你不在乎什么语言,grep NVSS file.txt>out.txt
  • @agentp 好吧,什么语言都没有关系;我不明白你所说的 grep NVSS file.txt>out.txt 是什么意思,请你解释一下

标签: python matlab wolfram-mathematica


【解决方案1】:

要将包含“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)

【讨论】:

  • 非常感谢,精彩而简单
猜你喜欢
  • 2020-05-18
  • 1970-01-01
  • 1970-01-01
  • 2014-06-03
  • 2013-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多