• 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: shell equivalent to text 1 thru -9?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shell equivalent to text 1 thru -9?


  • Subject: Re: shell equivalent to text 1 thru -9?
  • From: "Mark J. Reed" <email@hidden>
  • Date: Mon, 18 Apr 2005 16:40:59 -0400

The shell can't easily do string extraction by position, but it can certainly do it by matching and removing a known prefix or suffix.

That is, given

x="nameOfSomeApp_log.txt"

then

${x%_log.txt}

will be "nameOfSomeApp".

You could alsou se ${x%_*.txt} if you aren't sure what comes between the _ and the .txt; if that matches more than one part of the filename (because there are two _s), then it will cut off the shortest suffix it can; use %% instead of % to cut off the longest.

If you want to chop off a prefix, you can replace the % with a #.    ${x##*.} will return "txt".

If you really do want to do it by character position, it's doable, just ugly:

${x%${x#?????????}}



On 4/18/05, Jake Pietrykowski <email@hidden> wrote:
Hi,

This isn't a AS question, but rather I'm looking for an example of a shell
equivalent to the AS command text 1 thru -9?

   set x to "nameOfSomeApp_log.txt"
   set y to text 1 thru -9 of x

I want to return 'nameOfSomeApp'?

TIA,
Jake

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      ( 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

  • Follow-Ups:
    • Re: shell equivalent to text 1 thru -9?
      • From: "Mark J. Reed" <email@hidden>
References: 
 >shell equivalent to text 1 thru -9? (From: Jake Pietrykowski <email@hidden>)

  • Prev by Date: Re: How to Renew DHCP Lease
  • Next by Date: Re: shell equivalent to text 1 thru -9?
  • Previous by thread: Re: shell equivalent to text 1 thru -9?
  • Next by thread: Re: shell equivalent to text 1 thru -9?
  • Index(es):
    • Date
    • Thread