• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: string count in log file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string count in log file


  • Subject: Re: string count in log file
  • From: "Marc K. Myers" <email@hidden>
  • Date: Sat, 15 Sep 2001 01:51:58 -0400
  • Organization: [very little]

> Date: Fri, 14 Sep 2001 18:22:35 -0400 (EDT)
> From: Greg Sutherland <email@hidden>
> To: email@hidden
> Subject: string count in log file
>
> I'm very new to AS. I want to count the number of times a string appears
> in a logfile. I would appreciate someone pointing me to examples of the
> file I/O and string recognition.

This should give you what you want:

set theFile to (choose file with prompt "Pick the file to analyze:" of
type {"TEXT"})
set theRslt to (display dialog "Enter the string whose occurrences you
want to count:" default answer "")
set fileID to (open for access theFile)
try
set theText to (read fileID)
close access fileID
on error m number n
try
close access fileID
end try
error m number n
end try
set {od, AppleScript's text item delimiters} to {AppleScript's text item
delimiters, text returned of theRslt}
set theCount to (count text items of theText) - 1
set AppleScript's text item delimiters to od
display dialog "The string occurred " & (theCount as text) & " time(s)"
buttons {"OK"} default button 1

Watch out for line wraps! What appears on two lines in this message may
belong on a single line and will not compile unless you arrange things
that way in Script Editor.

Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[9/15/01 1:50:46 AM]


  • Prev by Date: Re: Scriptable Text Editor v.1.1
  • Next by Date: Re: problem in script
  • Previous by thread: string count in log file
  • Next by thread: Re: string count in log file
  • Index(es):
    • Date
    • Thread