Reading a specific line# in a file


How do read a specific line in a text file. Lets say i need to read word 2 of line 5.

Surprisingly enough:

set fileContents to read file "path:to:file"
return word 2 of paragraph 5 of fileContents

Note the use of the term ‘paragraph’ which may not coincide with visible lines.

Lines requires some element of visibility of the text since the line wraps will vary depending on the window width, font size, etc., etc. Paragraphs breaks the text based on line breaks/carriage returns and therefore doesn’t require any font scaling or window sizing to be taken into account.

It works :smiley:

Thanks a lot