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

Re: extracting fields



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.

Alternatively, if it is is the second field you want, you can
probably do:

   ${${pg_tables#*|}%%|*}

Oliver



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