我在 Unix 中有一个如下所示的文件
">hello"
"hello"
"newuser"
"<newuser"
"newone"
现在我想在文件中查找唯一出现的位置(仅在搜索时排除 <
或 >
),输出为:
">hello"
"<newuser"
"newone"
最佳答案
#!/usr/bin/env python
import sys
seen = set()
for line in sys.stdin:
word = line.strip().replace('>', '').replace('<', '')
if word not in seen:
seen.add(word)
sys.stdout.write(line)
$ ./uniq.py < file1
">hello"
"newuser"
"newone"
关于unix - 如何通过忽略特定模式来查找 Unix 文件中的唯一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17038003/