• 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
Working with big lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Working with big lists


  • Subject: Working with big lists
  • From: Rob Stott <email@hidden>
  • Date: Sun, 22 May 2005 19:58:10 +0100

Hi all,

I have a list in a text (.txt) file. I want to find out how many times each line occurs in the text file. For example, if the text file contained;

apple
apple
apple
orange
orange
pear

I want to be able to read it and get;

apple    3
orange    2
pear    1

...at the moment, I'm doing this with the following script, and it works.


set theResult to ""
set theFile to choose file
set theContents to every paragraph of (do shell script "cat " & quoted form of (POSIX path of theFile))

--remove duplicates using LNS's List and Record OSAX
set theNewList to difference of {} and theContents with removing duplicates

repeat with theItem in theNewList
    set theResult to theResult & theItem & "\t" & (do shell script "egrep -c " & quoted form of theItem & " " & quoted form of (POSIX path of theFile)) & "\r"
end repeat


...but some of the text files are REALLY long, and it takes quite a while. I was wondering whether anyone had any clever ideas for doing this a bit more quickly. Perhaps a big chunk of "do shell script" would speed things up, but it's still early days for me and shell scripting.

Any ideas or suggestions appreciated!

Thanks
Rob
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Working with big lists
      • From: kai <email@hidden>
    • Re: Working with big lists
      • From: Kim Hunter <email@hidden>
    • Re: Working with big lists
      • From: Daniel Jalkut <email@hidden>
References: 
 >Waiting for script to exit (From: Christopher Brown <email@hidden>)
 >Re: Waiting for script to exit (From: Emmanuel <email@hidden>)
 >Re: Waiting for script to exit (From: Christopher Brown <email@hidden>)

  • Prev by Date: Re: Waiting for script to exit
  • Next by Date: Getting Next and Previous Messages in Apple Mail
  • Previous by thread: Re: Waiting for script to exit
  • Next by thread: Re: Working with big lists
  • Index(es):
    • Date
    • Thread