【问题标题】:How can i extract duplicate lines from two text files?如何从两个文本文件中提取重复行?
【发布时间】:2014-08-04 08:14:43
【问题描述】:

我正在处理两个文本文件,其中一个是中间列中的名称 ic,在另一个中我只有名称,我需要提取包含名称的行的所有列在另一个文件中提到, 有人知道怎么做吗? 最好的, 托梅克

【问题讨论】:

  • 这些文本文件有任何列分隔符吗?你将如何从 txt 文件中获取第二列?
  • 到目前为止你做了什么?向我们展示您的文本文件和源代码的示例。
  • To be honest I haven't really done anything, this is how the name file looks: CHEMBL102582_entry_00018_conf_02 CHEMBL102582_entry_00018_conf_14 CHEMBL102582_entry_00018_conf_15 CHEMBL102582_entry_00018_conf_41 CHEMBL102582_entry_00018_conf_52 this is how the file from which i have to extract looks AffCHEMBL1288585 AffCHEMBL1288585_entry_00004_conf_01.mol2 -74.8107 10000001000000100000 0.473684 AffCHEMBL1288585 AffCHEMBL1288585_entry_00004_conf_02.mol2 -71.2064 00000001000101100000 0.611111 AffCHEMBL1288585 AffCHEMBL1288585_entry_00004_conf_03.mol2 -68.9659 00000001000101100000 0.588235
  • awk 很容易做到,并且有多个与此相关的问题/重复。如果您愿意接受非纯 python 解决方案,我建议您看看它。 PS:不要在评论中转储文本。 edit 你的答案。
  • @TomekStępniewski 请编辑您的问题并将您的数据放在那里。不要把它放在评论中。

标签: python bash


【解决方案1】:

如果cols 使用, 分隔列,您可以在bash 中使用类似的内容。

$ cat names
foo
bar
baz
$ cat cols 
1,foo,true
2,qux,false
3,bar,true
4,guux,false
$ cat names | while read name; do grep ",$name," cols; done
1,foo,true
3,bar,true

【讨论】:

    猜你喜欢
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 2018-11-11
    • 1970-01-01
    • 2014-07-11
    • 1970-01-01
    相关资源
    最近更新 更多