Das Problem wurde hier mal beschrieben. Man halt also 2 Tabellen und möchte die Werte aus beiden zusammenführen (addieren in diesem Fall). Nix andere tut dieses Script mit tab-separierten Dateien.
hier noch die Beispiel-Dateien zu ausprobieren...Testfile1 Testfile2 Theoretisch könnte man so etwas auch für Excel schreiben und die Daten einfach über die Zwischenablage einlesen....
damit werden carriage returns von mac in normale unix LF umgewandelt ist etwas zuverlässiger, man weiß ja nie, was einem für eine Text-Datei vorgesetzt wird =)
Zugehörige Zeilen zusammenführen
set file1 to quoted form of (POSIX path of ((choose file) as alias))
set file2 to quoted form of (POSIX path of ((choose file) as alias))
set mytempfile to "/tmp/a21239d511fe54d3b3ba661bc0a45a31.txt"
set thetext to (do shell script "cat " & file1 & " > " & mytempfile & ";echo ''>>" & mytempfile & ";cat " & file2 & " >>" & mytempfile & "; sort " & mytempfile)
set valueList to buildlist(thetext, tab)
repeat with i from 1 to count of every item of valueList
if i = 1 then
copy {item 1 of valueList} to finalvaluelist
else
if item 1 of item i of valueList = item 1 of last item of finalvaluelist then
set item 2 of last item of finalvaluelist to (item 2 of last item of finalvaluelist) + (item 2 of item i of valueList)
set item 3 of last item of finalvaluelist to (item 3 of last item of finalvaluelist) + (item 3 of item i of valueList)
else
copy finalvaluelist & {item i of valueList} to finalvaluelist
end if
end if
end repeat
set the clipboard to buildtext(finalvaluelist, tab)
display dialog "result is in clipboard"
on buildtext(llist, thedelimiter)
set AppleScript's text item delimiters to thedelimiter
repeat with i from 1 to count of llist
set item i of llist to item i of llist as text
end repeat
set AppleScript's text item delimiters to return
set llist to llist as text
set AppleScript's text item delimiters to ""
return llist
end buildtext
on buildlist(thetext, thedelimiter)
set thelines to every paragraph of thetext
set thevalues to {}
set AppleScript's text item delimiters to thedelimiter
repeat with theline in thelines
set tmp to every text item of theline
if (count of tmp) = 3 then
set thevalues to thevalues & {{item 1 of tmp, (item 2 of tmp) as integer, item 3 of tmp as integer}}
end if
end repeat
set AppleScript's text item delimiters to ""
return thevalues
end buildlist #
Kleiner Nachtrag
set thetext to (do shell script "tr '\r' '\n' <" & file1 & " > " & mytempfile & ";echo ''>>" & mytempfile & ";tr '\r' '\n' <" & file2 & " >>" & mytempfile & ";sort " & mytempfile)