• 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: Count word's occurences
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Count word's occurences


  • Subject: RE: Count word's occurences
  • From: "Lanphier, Daniel A." <email@hidden>
  • Date: Mon, 08 Sep 2014 12:47:12 +0000
  • Thread-topic: Count word's occurences

Try Os command “grep apple|wc –w”

 

 

Dan Lanphier
Systems Engineer • Systems Operations
w: 402.498.1567
| m: 402.680.0613

This message is privileged and confidential and is intended only for the use of the addressee. Unauthorized use of this message is strictly prohibited. If you received this transmission in error, please immediately contact the sender and destroy the message. Thank you.

 

 

From: applescript-users-bounces+daniel.lanphier=email@hidden [mailto:applescript-users-bounces+daniel.lanphier=email@hidden] On Behalf Of Guido Tangorra
Sent: Monday, September 8, 2014 2:53 AM
To: Applescript Users List
Subject: Count word's occurences

 

I'm generating a text document in TextWrangler, a sort of name list, dinamically with AS. 

This could be an example of the file I'm generating:

-----------

apple

grape

banana

ananas

orange

apple

apple

orange

--------------

 

I need to print the occurrences of every word in this document too.

So I would something like:

 

-----------

apple 1

grape 1

banana 1

ananas 1

orange 1

apple 2

apple 3

orange 2

--------------

 

I'm using this handler:

 

#Word Counter

on findLr(the_string, charTF)

            set AppleScript's text item delimiters to charTF --use of the searched string to separate bits

            set the_list to text items of the_string --put those bits in a list

            set charNbr to ((count of the_list) - 1) --count those bits, minus 1

            set AppleScript's text item delimiters to ""

            return charNbr

end findLr

 

This is working fine, but I'm wondering if there's a better or a more efficient way to do the same. Maybe with grep or ASObjC Runner or with a built-in command in TextWrangler.

The file has thousands of lines and it's generated dynamically so the performances are critical.

 

 

 _______________________________________________
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

References: 
 >Count word's occurences (From: Guido Tangorra <email@hidden>)

  • Prev by Date: Re: Count word's occurences
  • Next by Date: RE: Count word's occurences
  • Previous by thread: Re: Count word's occurences
  • Next by thread: RE: Count word's occurences
  • Index(es):
    • Date
    • Thread