比较和删除txt文件

时间:2014-01-12 12:26:46

标签: text compare comparison applescript

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

我尝试了各种比较程序,但是它们考虑了位置和字体等等。我的编程不足以改变设置(如果可能的话)。也许是Applescript中的东西?我用的是mac ...

实施例

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

2 个答案:

答案 0 :(得分:0)

尝试:

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

答案 1 :(得分:0)

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

非常感谢!!!