Re: Working with big lists
Re: Working with big lists
- Subject: Re: Working with big lists
- From: Kim Hunter <email@hidden>
- Date: Mon, 23 May 2005 10:51:20 +1000
Title: Re: Working with big lists
This is a stand alone idea of another way you could do it:
set thelist to {"apple", "orange", "pear"} as list
set theFile to choose file
set itemcount to {"0", "0", "0"}
repeat with i from 1 to (number of items in thelist)
set theitem to item i in thelist
set item i of itemcount to do shell script "grep -c " & theitem & " " & (POSIX path of theFile)
end repeat
repeat with i from 1 to (number of items in thelist)
set displaylist to item i of thelist & " " & item i of itemcount
end repeat
display dialog item 1 of thelist & " " & item 1 of itemcount & "
" & item 2 of thelist & " " & item 2 of itemcount & "
" & item 3 of thelist & " " & item 3 of itemcount
On 23/5/05 4:58 AM, "Rob Stott" <email@hidden> wrote:
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
_______________________________________________
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