When accessing a tab delimited file, any fields that contain commas are surrounded by quotes on output. For instance a tab delimited file that looks like this:
Contact Company
John Smith, President ABC Company
Will return:
"John Smith, President"
ABC Company
Here is the code that I am using. If you create a simple tab delimited file, it will loop through the fields and display the output.
set strTextFile to choose file with prompt "Choose a tab-delimited text file" of type {"TEXT"}
open for access strTextFile
set strDataFile to read strTextFile using delimiter return
close access strTextFile
set strList to {}
set text item delimiters to tab
repeat with intCounter from 1 to count of strDataFile
set strLine to text items of item intCounter of strDataFile
copy strLine to the end of strList
end repeat
set text item delimiters to ""
repeat with intRecords from 1 to count of strList
repeat with intFields from 1 to count of items in strList
set strOutput to item intFields of item intRecords of strList
display dialog strOutput
end repeat
end repeat
Please let me know if you have any questions. Any input on how to eliminate the quotes would be greatly appreciated.
set strTextFile to choose file with prompt “Choose a tab-delimited text file” --of type {“TEXT”}
open for access strTextFile
set strDataFile to read strTextFile using delimiter return
close access strTextFile
set strList to {}
set text item delimiters to tab
repeat with intCounter from 1 to count of strDataFile
set strLine to text items of item intCounter of strDataFile
copy strLine to the end of strList
end repeat
set text item delimiters to “”
repeat with intRecords from 1 to count of strList
set thisString to “”
repeat with intFields from 1 to count of items in strList
set strOutput to item intFields of item intRecords of strList
set thisString to thisString & strOutput
if intFields < (count (items in strList)) then
set thisString to thisString & return
end if
end repeat
display dialog thisString
end repeat
There’s a lot recounting and some text files don’t have file types. I just added on to what you had.
Run the script below with an actual tab delimited file to see what I mean.
set strTextFile to choose file with prompt "Choose a tab-delimited text file" of type {"TEXT"}
open for access strTextFile
set strDataFile to read strTextFile using delimiter return
close access strTextFile
set strList to {}
set text item delimiters to tab
repeat with intCounter from 1 to count of strDataFile
set strLine to text items of item intCounter of strDataFile
copy strLine to the end of strList
end repeat
set text item delimiters to ""
repeat with intRecords from 1 to count of strList
repeat with intFields from 1 to count of items in strList
set strOutput to item intFields of item intRecords of strList
--display dialog strOutput
return strList
end repeat
end repeat
What I need to do is return each of the values without quotes.