• 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 15:08:13 -0800

>>Doug McNutt >>It's hard to believe that you have the targeted file in the system's  root directory. Are you leaving out a leading "~" symbol?  $HOME/CatalogStuff/prdItem.txt is more likely. Surely choose file  includes the directory - doesn't it?

Choose file returns: alias "Jaguar:CatalogStuff:prdItem.txt"

If something is being left out (a ~ symbol or a directory) that's happening in the "POSIX path of" coercion which returns: "/CatalogStuff/prdItem.txt" from that alias. Bug, no?

>>>The return you're adding will be a Mac line end and it looks as  though it's being treated as a part of the path. Take it out.

Without the return I get "An error of type 1 has occurred" message.

>>Has>>>In this case, 'grep' is failing because you're giving it the string "/CatalogStuff/prdItem.txt\r" as its path argument (note the return character on the end).
Remember, Unix uses linefeeds, not carriage returns; if you use a CR where you should be using a LF, bad things happen.

Ok... I'!
 m kind of hazy on this whole good bad thing...  define bad.

>>>>>ALWAYS USE THE QUOTED FORM when composing arbitrary AS strings as command arguments in a shell script. If you don't understand why this is so important, you're not safe to be using the command line in the first place.

Not safe. One more reason to prefer pure AppleScript to shell scripting.

Thanks to help from this list, I got the shell script in a workable form

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

I getting the desired result almost instantly.

The problem is if the target file is on the top level of the startup volume or on the network, it still  doesn't work, giving me either "type 1 error" or "input/output error". (This script is meant for users off-site who, as mac users do, put files wherever they damn well feel like it, so unless this!
  can be fixed we can't use it.)

This really shouldn't be thi!
 s diffic
ult.

Ed
 _______________________________________________
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: Deivy Petrescu <email@hidden>
    • Re: Finding lines containing foo in a file
      • From: Emmanuel <email@hidden>
  • Prev by Date: Re: How can I set a background image to a Volume ?
  • Next by Date: Re: Best practices for creating and comparing lists of text?
  • 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