ASTID & "return" character ASCII

I am trying to parse data from a text report generated by a piece of software called semaphore. It is more or less a CSV file however there is no comma after the last item before the line break which is attaching the last item of line 1 and the first item of line 2.

Is there any way to set the ASTID to “return” and replace with 'comma" then do a second ASTID to parse the data between each comma?

here is what the text file looks like:

“Alert Type”,“Start Frame”,“Time Code”,“DirectShow Time”,“Total Frames”

You can try using something like this:

set dataFile to choose file with prompt "Please select the text file."
set findReplaceList to read dataFile using delimiter (ASCII character 10)
log findReplaceList
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}

repeat with i from 1 to count of findReplaceList
	set item i of findReplaceList to every text item of item i of findReplaceList
end repeat
set AppleScript's text item delimiters to ASTID
return findReplaceList

ASCII character 10 should be the return you are looking for which will give you a list of the items on each line. The repeat loop will create a nested list for each item from the comma separated items on the line. The returned list should look like this:

Where the first item in the list is a nested list of the column titles, shown here with the parens escaped.

That works pretty well however there is still a return character attached to the last value of each list.
I am making a new text file with these last values and would prefer if the return character wasn’t included in the result.



Change this line in Jerome’s script:

set findReplaceList to read dataFile using delimiter (ASCII character 10)

. to this:

set findReplaceList to paragraphs of (read dataFile)

Then you don’t have to second-guess what line endings have been used in the file. AppleScript takes care of them for you.