Zugehörige Zeilen zusammenführen
25/04/2010set 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)