• 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: Parsing Large Text Files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parsing Large Text Files


  • Subject: Re: Parsing Large Text Files
  • From: "Nigel Garvey" <email@hidden>
  • Date: Fri, 2 May 2008 12:02:09 +0100

Bruce Robertson wrote on Thu, 01 May 2008 21:37:31 -0700:

>Mark's perl script is way fast, here is what I was attempting in applecript.

Perl's obviously the way to go in your case, but I can't resist tinkering
with the AS performance.  :)  This uses File Read/Write instead of the
shell script, 'set' instead of 'copy', referenced list variables, and a
more efficient way of inserting returns into the reversed text:

  set f to read (choose file)
  set astid to AppleScript's text item delimiters
  set AppleScript's text item delimiters to ">"
  set f to text items of f
  set AppleScript's text item delimiters to ""

  set fRef to (open for access file ((path to desktop as Unicode text) &
"new.txt") with write permission)
  try
    set eof fRef to 0
    set t to current date -- Equivalent timing start point.
    repeat with num from 1 to (count f)
      set thisOne to item num of my f
      if ((count thisOne) > 0) then
        set thisOne to paragraphs of thisOne
        set newtext to ">" & item 1 of my thisOne
        try
          set otherLines to rest of my thisOne
          set newtext to newtext & return & reverseMe(otherLines as text)
        on error
          -- beep
        end try
        write newtext as string to fRef
      end if
    end repeat
  end try
  close access fRef
  set AppleScript's text item delimiters to astid
  set f to ""
  beep
  display dialog ((current date) - t)

  on reverseMe(what)
    script o
      property l : (reverse of (characters of what))
    end script

    set len to (count what)
    repeat with i from 50 to len by 50
      set item i of o's l to item i of o's l & return
    end repeat
    if (i is not len) then set item len of o's l to item len of o's l & return
    return o's l as text
  end reverseMe


NG

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Parsing Large Text Files
      • From: Bruce Robertson <email@hidden>
  • Prev by Date: Re: Sending an application to the Dock?
  • Next by Date: Re: XMLNextSibling is there an easier way
  • Previous by thread: Re: Parsing Large Text Files
  • Next by thread: Re: Parsing Large Text Files
  • Index(es):
    • Date
    • Thread