Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: extracting fields



On Mon, Dec 22, 2003 at 10:51:54AM +0100, Oliver Kiddle wrote:
> Dominic Mitchell wrote:
> > I'm trying to extract stuff from a string in a similiar manner to cut(1)
> > and getting rather unstuck.  I'm sure that there's a simpler answer, but
> > I can't seem to find it.
> 
> > Now I'm interested in the table name which is the 2nd field.  But I
> > can't work out how.  I've been playing with things like this:
> > 
> >     % echo ${(@s:|:)pg_tables[2]}
> 
> Zsh has no concept of two-dimensional arrays so you can't split every
> element of an array and expect indexing tow work on each element like
> that. You would have to have a for loop for each array element.

Aha, thank you.  I was thinking that I could do it in a for loop.

> Alternatively, if it is is the second field you want, you can
> probably do:
> 
>    ${${pg_tables#*|}%%|*}

That's perfect.  Thank you very much.  Funnily enough, I started going
down that line, until I realised I was interested in the second field,
not the first.  I got the %%|* bit, but didn't make the leap to
stripping the first field.

Many thanks,
-Dom



Messages sorted by: Reverse Date, Date, Thread, Author