• 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: Christopher Stone <email@hidden>
  • Date: Mon, 08 Sep 2014 10:22:59 -0500

On Sep 08, 2014, at 02:53, Guido Tangorra <email@hidden> wrote:
I'm generating a text document in TextWrangler, a sort of name list, dynamically with AS. 
______________________________________________________________________

Hey Guido,

Change BBEdit to TextWrangler as needed in the script.

When run from a 10,000 word file or BBEdit window using your example words the run-time is less than 2/10 of a second on my system.

--
Best Regards,
Chris

______________________________________________________________________

apple    3750
banana   2500
bananas  1250
grape    1250
orange   2500

-------------------------------------------------------------------------------------------
# From a file.
-------------------------------------------------------------------------------------------

set shCMD to text 2 thru -1 of "
#!/bin/bash

F=~/\"test_directory/BBEdit_Test_Dir/test-grep-wc.txt\";
T=$(cat $F);
S=$(sort -u <<< \"$T\");
A=\"\";

for i in $S
do
X=$(grep \"$i\" <<< \"$T\" | wc -w);
A=\"$A$i $X\\n\";
done
echo \"$A\" | column -t;
"
do shell script shCMD without altering line endings

-------------------------------------------------------------------------------------------
# Directly from a BBEdit or TextWrangler window.
-------------------------------------------------------------------------------------------

tell application "BBEdit"
set _text to contents of front text window
set _text to replace "\\A\\s+|\\s+\\Z" using "" searchingString _text options {search mode:grep}
set _text to _text & linefeed
end tell

set shCMD to text 2 thru -1 of "
#!/bin/bash

T=$(tr '\\r' '\\n' <<< " & quoted form of _text & ");
S=$(sort -u <<< \"$T\");
A=\"\";

for i in $S
do
X=$(grep \"$i\" <<< \"$T\" | wc -w);
A=\"$A$i $X\\n\";
done
echo \"$A\" | column -t;
"
do shell script shCMD without altering line endings

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

 _______________________________________________
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: Count word's occurences
      • From: Christopher Stone <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