It is said that there is no such thing as a stupid question - let's see:

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Sun Jan 26 14:53:51 AEST 1986


> Is there a way to dimension buffers (arrays) in scripts,  and selectivly extract
> portions/fields of data from them?  I would like to also be able to do this with
> buffers in the B and C shells.
> 
> Example:
> 
>   LONG_THANKS="Thanksinadvanceforallyourhelp"
>  
> I want to take columns 1-5, add a space, and add columns 22-24. and set them into
> the buffer SHORT_THANKS.

You can't readily do this without the aid of string-handling
utilities; I seem to recall some substring utilities posted
to the net within the past year.  (The Korn shell has some
additional facilities built in that would help.)

The System V utility "cut" can be used to extract fields from
strings, e.g.

SHORT_THANKS=`echo "$LONG_THANKS" | cut -c1-5`\ `echo "$LONG_THANKS" | cut -c22-24`

This isn't ideal, but it may serve your needs (strange as they are).



More information about the Comp.unix mailing list