• 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: Finding lines containing foo in a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Finding lines containing foo in a file


  • Subject: RE: Finding lines containing foo in a file
  • From: "Stockly, Ed" <email@hidden>
  • Date: Wed, 21 Dec 2005 11:32:28 -0800

	 Hi, Thanks for the quick and helpful responses.
	 >>deivy>>set end of found to (do shell script gr & j & "  " & filepath) &

	OK, here's one reason I prefer pure AppleScript to shell scripting:

set itemNumber to "25307"
set filepath to POSIX path of (choose file)
set myShellScript to ("grep " & (itemNumber as string) & " " & filepath & return) as string
set foundLines to (do shell script myShellScript)

--appleScript error
--do shell script "grep 25307 /CatalogStuff/prdItem.txt
--"
--		"grep: /CatalogStuff/prdItem.txt
--: No such file or directory"

	I know the file is there. I know the string I'm looking for is in the file. I've reduced the shell script to the simplest possible form.

	I've tried several variations of the script. I've tried it with the file in several locations. I've even renamed the file to exactly match the version Deivy suggested and I still get the same error. I've tried it on 3 different macs with three different OS X versions.

	What am I missing?




> >I am currently doing this by reading the file, getting the offset of each
> >string, finding the line number from its position in the text and
> >extracting the line using text item delimiters.
>
>>NG>>>You can also do it the other way round: set the TIDs to the string, count
> the paragraphs of the "first text item" of the file text, and extract the
> that-numbered paragraph. It doesn't use any OSAX calls during the repeat;
> but not having seen your original code, I can't tell if it's a great
> improvement ...
>
I'll give it a try, it may be. That gives me another idea, that I'll also test:

Set the TIDs to the string, then get the last line of item 1 & the first line of item 2 . (This would actually save me a step in extracting fields from records)

I'll also test to see if TIDs is faster than getting the offset and if I ever figure out what's wrong with my shell script (above) it'll test and compare that too.

Thanks

ES

 _______________________________________________
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

  • Follow-Ups:
    • Re: Finding lines containing foo in a file
      • From: Paul Berkowitz <email@hidden>
    • RE: Finding lines containing foo in a file
      • From: Doug McNutt <email@hidden>
  • Prev by Date: Re: How can I set a background image to a Volume ?
  • Next by Date: RE: Finding lines containing foo in a file
  • Previous by thread: Re: Finding lines containing foo in a file
  • Next by thread: RE: Finding lines containing foo in a file
  • Index(es):
    • Date
    • Thread