在 txt 文件中比较和删除



我想要一些脚本或程序来比较文本文档,并在两个文本中找到相同的电子邮件地址,并创建一个新文件,其中仅出现在两个中的一个中的电子邮件地址保留(两个文件中出现的电子邮件地址已在此新文本文件中删除)。

我尝试了各种比较程序,但它们考虑了位置和字体等。我的编程不够好,无法更改设置(如果可能的话)。也许苹果脚本中的某些内容?我使用电脑...

Text1: 
a@mail.x
b@mail.x
c@mail.x
e@mail.x
a@mail.x <--(yes, that's a duplicate... I would like to have them deleted as well)
Text2:
b@mail.x
c@mail.x
a@mail.x
d@mail.x
Text3:
d@mail.x
e@mail.x

尝试:

set compareDocs to choose file with prompt "Select files to compare" with multiple selections allowed
set uniqueItems to {}
repeat with aDoc in compareDocs
    set addresses to paragraphs of (read aDoc as «class utf8»)
    repeat with address in addresses
        set address to contents of address
        if address is not in uniqueItems then
            set end of uniqueItems to address
            set end of uniqueItems to linefeed
        end if
    end repeat
end repeat
set parentFolder to POSIX path of ((first item of compareDocs as text) & "::")
set parentFolder to parentFolder & "Unique_Addresses.txt"
set uniqueItems to uniqueItems as text
do shell script "echo " & quoted form of uniqueItems & " > " & quoted form of parentFolder

在Excel中找到了一种满足我需求的方法(删除重复项)。

无论如何,谢谢!!

相关内容

  • 没有找到相关文章

最新更新