Read before issues

Hello all,

Got a little oddity here which I need some help with.

I’m trying to read data a line at a time from a file. The code I used to use was:

set refnum to open for access aFile

try
	repeat while true
		set lineofdata to read refnum before return
		
		if lineofdata contains stringToLookFor then
						
		end if
		
	end repeat
on error
	exit repeat
end try
if refnum ≠ 0 then close access refnum

My problem is this, it does not work under OS X, and I’m guessing that is due to unix line endings in the file. Now, I thought I could simply pop in “\n” in place of “return” but it’s not working as it should, it’s not delimited on the end line character.

So, how or what do I use to read a file line by line? even if I read the whole file into a variable and search through it I still encounter the same issue.

TIA

You could try this:

set lineofdata to read refnum before (ASCII character 10)

Why thank you! That works perfectly :slight_smile: