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

Re: Substituting all but a trailing digit/number



On Fri, Jul 13, 2007 at 01:22:56PM +0000, zzapper wrote:
> Peter Stephenson <pws@xxxxxxx> wrote in news:200707131248.l6DCmHAI018710
> @news01.csr.com:
> 
> > zzapper wrote:
> >> 
> >> I want to generalise top3 into top4,top5..etc
> >> 
> >> But how could I get filter just the trailing number (in VIM I would use 
> >> memory)
> > 
> > Use
> > 
> >   num=${(M)0%%<->}
> > 
> > The (M) tells the shell to substitute the matched part instead of
> > removing the matched part.
> Thanks Peter,
> And If I wanted to anchor the number to the end?
[...]

%% matches at the end, as much as possible.

You could also do

num=${0##*[!0-9]}

(remoes everything up to the rightmost non-digit).

That even happesns to  be POSIX.

Also, why are you using ls?

Why not simply

gvim -p *(.om[1,$num])

-- 
Stéphane



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