gpt4 book ai didi

unix - unix下如何从2个文件中找到匹配的记录

转载 作者:行者123 更新时间:2023-12-02 21:30:56 24 4
gpt4 key购买 nike

我有两个包含 email_ids 的文件。1.测试1.txt2.Test2.txt

Test1.txt内容为:

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b0a09082b0c060a020745080406" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80f8f9fac0e7ede1e9ecaee3efed" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b4645586b4c464a424705484446" rel="noreferrer noopener nofollow">[email protected]</a>

Test2.txt内容为:

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="315b415671565c50585d1f525e5c" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aec4c1d7eed7cfc6c1c180cdc1c3" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2140434261464c40484d0f424e4c" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d0d18093d041c151212531e1210" rel="noreferrer noopener nofollow">[email protected]</a>

这里[email protected]是 Test1.txt 和 Test2.txt 之间的公共(public) ID。我想从这两个文件中找出这样的 Id 并将它们插入到一个文件中。

请提出建议。我只需要这两个文件之间共有的 ID。

最佳答案

您也可以使用 grep 执行此操作:

grep -Fwf Test1.txt Test2.txt

$ head t*
==> t1 <==
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3051525370575d51595c1e535f5d" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9d1d0d3e9cec4c8c0c587cac6c4" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9df0f3eeddfaf0fcf4f1b3fef2f0" rel="noreferrer noopener nofollow">[email protected]</a>

==> t2 <==
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d170d1a3d1a101c1411531e1210" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="42282d3b023b232a2d2d6c212d2f" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3b2b1b093b4beb2babffdb0bcbe" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b3b2e3f0b322a23242465282426" rel="noreferrer noopener nofollow">[email protected]</a>

$ grep -Fwf t1 t2
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bbdad9d8fbdcd6dad2d795d8d4d6" rel="noreferrer noopener nofollow">[email protected]</a>

关于unix - unix下如何从2个文件中找到匹配的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22294448/

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