2014-01-12 92 views
0

我想要一些腳本或程序來比較文本文檔,並在兩個文本中找到相同的電子郵件地址,並創建一個新文件,其中僅出現在兩個文件中的一箇中的電子郵件地址(在這兩個文件中出現的文件已經在這個新的文本文件中被刪除)。在txt文件中比較和刪除

我試過各種比較程序,但他們考慮到位置和字體等,等等。我的編程不足以改變設置(如果這是可能的話)。也許在Applescript中有什麼?我使用的是Mac ...

Text1: 

[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] <--(yes, that's a duplicate... I would like to have them deleted as well) 

Text2: 

[email protected] 
[email protected] 
[email protected] 
[email protected] 

Text3: 

[email protected] 
[email protected] 

回答

0

發現在Excel(刪除重複),用作我的需求的一種方式。

謝謝!

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 
+0

我用我給出的例子作爲一個測試,雖然它做了一些它不做我想要的東西。 這是結果: [email protected] [email protected] [email protected] [email protected] [email protected] 感謝您的快速回復。我希望解決方案接近! – Mauritz

+0

也許我的例子不清楚......我想比較文本1和文本2,以便結果會像文本3 – Mauritz