Re: counting the records in a tab-delimited text file
Re: counting the records in a tab-delimited text file
- Subject: Re: counting the records in a tab-delimited text file
- From: Kai Edwards <email@hidden>
- Date: Sat, 22 Dec 2001 15:19:33 +0100
>
Subject: Re: counting the records in a tab-delimited text file
>
From: Bill White <email@hidden>
>
To: Robert Castles <email@hidden>, =AppleScript
>
Mailing List <email@hidden>
>
>
> Can anyone give me a simple way of counting the number of records
>
> (return-delimited records) in a tab-delimited text file? I know I can go
>
> through and read each character, counting each return, but that seems like a
>
> really inefficient way of getting the count. Thanks in advance,
>
>
>
Try using text item delimiters:
>
>
set theFile to read file "Hard drive:Desktop folder:Text file" -- change to
>
suit
>
>
set oldDelims to AppleScript's text item delimiters
>
set AppleScript's text item delimiters to return
>
>
set recordCount to (count (text items of theFile)) - 1
>
>
set AppleScript's text item delimiters to oldDelims
>
>
return recordCount
Recently, in response to another question, I suggested a similar approach
(using text item delimiters). However, Michelle Steiner then offered a much
more direct solution using 'count paragraphs' - which could simplify the
script to something like this:
set theFile to read file "Hard drive:Desktop folder:Text file" -- change to
suit
set recordCount to (count paragraphs of theFile) - 1
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************