On Oct 18, 2009, at 17:37, le...@gmail wrote:
> I have a fairly long fortune file (http://home.kreme.com/mysigs.txt )
> that I would like to sort in alphabetic order, excepting leading
> punctuation or supper common words like 'a', 'the', 'I', &c.
> ...
> Ideas?  Probably a perl script, huh?
______________________________________________________________________

Hey Lewis,

Just for fun let's try Applescript and some regex.

Dependent upon the Satimage.osax for regex & split/join functions:
   http://www.satimage.fr/software/downloads/Satimage340.dmg

In addition to the exclusion list all possessives and contractions  
within a certain character length are removed from the beginning of  
quotes before the sort.

It ought to be easy enough to use BBEdit for the regex if preferred.

Runs in about a second on my old g4 PowerBook with your sig file.

That was fun.  :)

--
Chris

#=======================================================================
#  Input: A file on the desktop named "mysigs.txt"
# Output: A file on the desktop named "sortedSigFile.txt"

# Script is expecting line endings to be newline characters
# as in the sig page saved from the internet via Safari.

property nLine : ASCII character 10
on cngText(srcData, fndStr, cngStr, caseFlag)
        set theResult to change fndStr into cngStr in srcData case sensitive  
caseFlag with regexp
end cngText
set exludeList to "
a
by
I
if
is
may
that
the
this
when
"
try
        set exludeList to items 2 thru -2 of (splittext exludeList using "\ 
\s" with regexp)
        set exludeList to "(\\b(" & (join exludeList using "|") & ")\\b\\s+)*"
        set dskTop to path to desktop as string
        set sigFile to (dskTop & "mysigs.txt") as alias
        set sigText to "%" & nLine & (read sigFile)
        set sigText to cngText(sigText, "\\s+\\Z", "\\n", false) of me
        set sigText to cngText(sigText, "(%\\n)(.+\\n)", "\\1\\2\\2", false)  
of me
        set sigText to cngText(sigText, ("(%\\n)(\\W*)(\\w{1,6}'\\w{1,2}\\s 
+)*" & exludeList), "\\1", false) of me
        set sigText to splittext sigText using "%\\n"
        set sigText to items 2 thru -1 of sigText
        set sigText to sortlist sigText
        set sigText to join sigText using ("%" & nLine)
        set sigText to cngText(sigText, "(%\\n)(.+\\n)", "\\1", false) of me
        set newFilePath to dskTop & "sortedSigFile.txt"
        try
                set f to open for access newFilePath with write permission
                set eof of f to 0
                write sigText to f
                close access f
        on error
                try
                        close access f
                end try
        end try
on error errMsg number errNum
        beep
        display dialog errMsg & return & return & "Error Number: " & errNum
end try
#=======================================================================


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
-~----------~----~----~----~------~----~------~--~---

Reply via email to