Code: Select all
-- Split the lines into an array for easy manipulation
split tData3 by return
-- Initialize a dictionary to hold grouped lines by item 1
put empty into groupedLines
-- Group lines by the first item
repeat for each line currentLine in tData3
put item 1 of currentLine into groupKey
if groupKey is not among the keys of groupedLines then
put currentLine into groupedLines[groupKey]
else
put return & currentLine after groupedLines[groupKey]
end if
end repeat
-- Process each group to ensure all "Plate Processor East"
repeat for each key groupKey in groupedLines
put groupedLines[groupKey] into groupLines
split groupLines by return
-- Check if any line in the group has "Plate Processor East"
put false into foundEast
repeat for each line lineItem in groupLines
if item 14 of lineItem is "Plate Processor East" then
put true into foundEast
exit repeat
end if
end repeat
-- If found, set all lines in the group to "Plate Processor East"
if foundEast then
repeat for each line lineItem in groupLines
put "Plate Processor East" into item 14 of lineItem
end repeat
end if
-- Combine the group lines back
combine groupLines by return
put groupLines into groupedLines[groupKey]
end repeat
-- Combine all groups back into a single variable
put empty into tResult
repeat for each key groupKey in groupedLines
put groupedLines[groupKey] & return after tResult
end repeat
delete the last char of tResult -- Remove the trailing return character