• 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: "koenig.yvan" <email@hidden>
  • Date: Mon, 08 Sep 2014 18:25:56 +0200


Le 08/09/2014 à 17:57, Lanphier, Daniel A. <email@hidden> a écrit :

APPLE=`grep -i apple FILENAME|wc –w`

BANANA=`grep -i  banana FILENAME|wc –w`

echo “Apple ${APPLE}”

echo “Banana ${BANANA}”

 

 

Dan Lanphier 

(1) Glad to see that you sent your message directly to my mailbox. I didn’t received it thru the list.

(2) I translated your code into AppleScript language :

set leFichier to (path to desktop as text) & "forGrep.txt"
set appleCount to my countOfKeyInSource(leFichier, " apple ")
set grapeCount to my countOfKeyInSource(leFichier, "grape")

on countOfKeyInSource(theSource, theKey)
return do shell script "grep " & theKey & space & (quoted form of POSIX path of theSource) & "|wc -w"
end countOfKeyInSource

And of course it give the same puzzling results than the original version.

When the occurrences are only text ones, the result is OK.
When an occurrence is just before a number, for instance "apple 3" it's counted twice.

I don’t know if such case may exist in the original asker's datas but, at least for me, it's SURPRIZING.

The new message posted by Omar K N pushed me in an interesting direction :
when an occurrence is available in a paragraph containing x "words", it's counted x times.
With this text
-----------
a0 apple a2 a3 a4 a5 a6
grape 1
banana 1
ananas 1
orange 1
apple
apple
orange 2
--------------
the result is :
apple 9
grape 2

I’m sure that it’s not the wanted result.

After reading your late message (received thru the list), I tried to use " apple " as the key and got exactly the same results.

Yvan KOENIG (VALLAURIS, France) lundi 8 septembre 2014 18:25:51






 _______________________________________________
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>)
 >RE: Count word's occurences (From: "Lanphier, Daniel A." <email@hidden>)
 >Re: Count word's occurences (From: "koenig.yvan" <email@hidden>)
 >Re: Count word's occurences (From: "email@hidden" <email@hidden>)
 >Re: Count word's occurences (From: "koenig.yvan" <email@hidden>)
 >RE: Count word's occurences (From: "Lanphier, Daniel A." <email@hidden>)

  • Prev by Date: RE: Count word's occurrences
  • 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