hello" "hello" "newuser" "),输出为: ">hello" "', '').replace('hello" "newuser" "n-6ren">
gpt4 book ai didi

unix - 如何通过忽略特定模式在 Unix 文件中查找唯一行

转载 作者:行者123 更新时间:2023-12-02 22:00:27 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com