KSH substring function (is it on your system?)
BALDWIN
mike at whuxl.UUCP
Thu Nov 14 14:49:07 AEST 1985
> As long as we're talking about 'substring', 'expr' has a 'substr' option
> that used to be documented in V6.
>
> It goes:
> expr substr string n m
>
> where n is the first character of the sub-string and m the length.
>
> so: expr substr abcdefgh 2 4
> gives: bcde
>
> 'expr' also has 'match', 'lentgh', and 'index' options that are not
> documented any longer. Anyone knows why?
The ":" operator of expr now handles all of these cases (I've never
heard of "index"; what does it do?):
-- old -- -- new --
expr match string regexp expr string : regexp
expr length string expr string : '.*'
expr substr string off len expr string : '.\{off-1\}\(.\{len\}\)'
Of course, you have to make sure that "string" isn't a valid expr
operator. Putting an ordinary char like _ at the beginning of both
the string and the regexp will fix that.
--
Michael Baldwin
{at&t}!whuxl!mike
More information about the Comp.unix
mailing list