• 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: How can I perform following task
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I perform following task


  • Subject: Re: How can I perform following task
  • From: "email@hidden" <email@hidden>
  • Date: Thu, 16 Dec 2010 08:23:58 -0800

I know this has been solved, but it could also be done in plain vanilla applescript with no need for any OSAX or shell.

OMM, the script below takes 5 seconds.

Of course, shell scripting and grep may be faster, but based on the Bert's request, AppleScript is probably fast enough.

ES

--------------------
property myText : ""
set startTime to current date
set barcodeFile to alias "Macintosh HD:Users:edstockly:Desktop:barcodetest"
set myText to read barcodeFile
repeat 100 times
	set myBarcodeNr to "8717545743119"
	set AppleScript's text item delimiters to {myBarcodeNr}
	set myText to text items of myText
	set articleNumber to the last word of item 1 of myText
end repeat
set endTime to current date
set elapsedTime to endTime - startTime


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


On Dec 16, 2010, at 3:35am, Bert Groeneveld wrote:

> Given a tab delimited .txt file (named codes.txt) that has a format like this:
> Articlenr.	Barcodenumber	Type	Description
> 010013	5602007143664	EAN13	FAXPAPER A4  (PACK A 500)
> 010014	8717545743119	EAN13	ORANGE T-SHIRT
> 010020	7640115940186	EAN13	TONER CANON E30 TBV FC2XX
>
> I show only a header and 3 lines here, but the actual file has a header and 27,000 lines
>
> Question: How can I (as quickly as possible) perform the following task with applescript:
> Given a barcodenumber as string, for example, I know the value of myBarcodeNr which is: set myBarcodeNr to  "8717545743119"
> I need to find out the corresponding articlenumber that stands before the barcodenumber on the same line of the tab delimited txt file, in this example that would be articlenumber "010014" and store that value in a variable myArticleNr.
>
> Hope someone can help with a smart piece of code that executes fast (I hope in just a few seconds).
>
> Thanks in advance,
> Bert.
> _______________________________________________
> 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

 _______________________________________________
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: 
 >How can I perform following task (From: Bert Groeneveld <email@hidden>)

  • Prev by Date: How do you eval strings as enumerators in 10.6?
  • Next by Date: What Use Autofill
  • Previous by thread: Re: How can I perform following task
  • Next by thread: Re:How to keep PhotoShop CS4 Save for Web plug-in from truncatingfilenames to 32 chars
  • Index(es):
    • Date
    • Thread