Brian Kernighan, in a lecture at the University of Nottingham, described a problem on which this task is based.

Problem

You are given a a data file of thousands of lines; each of three `whitespace` separated fields: a date, a one word name and the magnitude of the event.

Example lines from the file would be lines like:

8/27/1883    Krakatoa            8.8
5/18/1980    MountStHelens       7.6
3/13/2009    CostaRica           5.1
Task

 Create a program or script invocation to find all the events with magnitude greater than 6
 Assuming an appropriate name e.g. "data.txt" for the file:
 Either: Show how your program is invoked to process a data file of that name.
 Or: Incorporate the file name into the program, (as it is assumed that the program is single use).


on kernighansEarthquakes(magnitudeToBeat)
    -- A local "owner" for the long AppleScript lists. Speeds up references to their items and properties.
    script o
        property individualEntries : {}
        property qualifyingEntries : {}
    end script
 
    -- Read the text file assuming it's UTF-8 encoded and get a list of the individual entries.
    set textFilePath to (path to desktop as text) & "data.txt"
    set earthquakeData to (read file textFilePath as «class utf8»)
    set o's individualEntries to earthquakeData's paragraphs
    -- Get the input magnitude in text form now rather than coercing it during the repeat.
    set magnitudeToBeat to magnitudeToBeat as text
 
    -- Check the entries with AppleScript's text item delimiters set to likely white space characters and considering numeric strings.
    -- With these delimiters, the entries' magnitudes will be the last 'text item' in each line
    -- (assuming for this exercise that there'll never be white space at the end of any of the lines).
    -- Store entries with qualifying magnitudes in a new list.
    set astid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {space, tab, character id 160} -- White space characters.
    considering numeric strings -- Compare numbers in strings numerically instead of lexically.
        repeat with i from 1 to (count o's individualEntries)
            set thisEntry to item i of o's individualEntries
            if (thisEntry's last text item > magnitudeToBeat) then set end of o's qualifyingEntries to thisEntry
        end repeat
    end considering
 
    -- Coerce the list of qualifying earthquakes to a single, linefeed-delimited text and return the result.
    set AppleScript's text item delimiters to linefeed
    set largeEarthquakes to o's qualifyingEntries as text
    set AppleScript's text item delimiters to astid
 
    return largeEarthquakes
end kernighansEarthquakes
 
kernighansEarthquakes(6)