• 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: Martin Orpen <email@hidden>
  • Date: Wed, 20 Apr 2005 00:21:37 +0100

on 19/4/05 23:54, Christopher Nebel at email@hidden wrote:

> On Apr 19, 2005, at 6:40 AM, Chris Janton wrote:
>
>>> 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.
>>>
>>>  x="nameOfSomeApp_log.txt"
>>
>> Sure it can (bash in this example) it just needs to be specified
>> properly.
>>
>> To get the length of a string - ${#x}
>> To get everything but the last 8 characters  - ${x: 0: ${#x}-8}
>>
>> That's STRING : offset : number of characters
>
> I find cut(1) to be very useful for this sort of thing, though it
> can't handle this particular case, since it has no way to specify
> positions relative to the end of the line.

But, in the example given by the OP, cut gets the job done:

    echo 'nameOfSomeApp_log.txt' | cut -d _ -f1

Guess it depends on whether the names are more likely to vary in delimiter
or length :(

--
Martin Orpen


 _______________________________________________
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

References: 
 >Re: shell equivalent to text 1 thru -9? (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: Shell script
  • Next by Date: Re: Shell script
  • Previous by thread: Re: shell equivalent to text 1 thru -9?
  • Next by thread: Scripting in quark...
  • Index(es):
    • Date
    • Thread