gpt4 book ai didi

macos - 找到 4 个文件的交集

转载 作者:行者123 更新时间:2023-12-04 19:01:55 26 4
gpt4 key购买 nike

你如何找到4个文件的交集?

我用了grep -Fx -f 1.txt 2.txt 3.txt 4.txt ,但它似乎只适用于 2 个文件。同样comm -12 1.txt 2.txt无法扩展为 4 个文件,需要对数据进行排序。我的数据没有排序,事实上,它不应该排序。我在 Mac 上。

输入:

1.txt
.css
.haha
.hehe
2.txt
.ajkad
.shdja
.hehe

3.txt
.css1
.aaaaa
.hehe

4.txt
.qwqw
.kkkmsm
.hehe

输出: .hehe
我首先在存储在 12.txt 中的 1 和 2 上使用 grep,然后在 3 和 4 上使用存储在 34.txt 中的 grep,然后在 12.txt 和 34.txt 中再次使用 grep。但是必须有更好的方法来做到这一点。

最佳答案

您可以链接 greps:

grep -f 1.txt 2.txt \
| grep -f- 3.txt \
| grep -f- 4.txt
-f-表示使用来自管道的输入,而不是真实文件。

关于macos - 找到 4 个文件的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40221014/

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