* Substituting all but a trailing digit/number
@ 2007-07-13 12:25 zzapper
2007-07-13 12:48 ` Peter Stephenson
0 siblings, 1 reply; 5+ messages in thread
From: zzapper @ 2007-07-13 12:25 UTC (permalink / raw)
To: zsh-users
I want to generalise top3 into top4,top5..etc
function top3()
{
# description : vi 3 newest files
file=$0
num=${file//[[:alpha:]]/}
gvim.exe -p $(l\s *(.om[1,$num])) &
}
In the above substitution I get the "number" by stripping out the alphas
which is kind of a trick
But how could I get filter just the trailing number (in VIM I would use
memory)
--
zzapper
http://www.rayninfo.co.uk/vimtips.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Substituting all but a trailing digit/number
2007-07-13 12:25 Substituting all but a trailing digit/number zzapper
@ 2007-07-13 12:48 ` Peter Stephenson
2007-07-13 13:22 ` zzapper
0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2007-07-13 12:48 UTC (permalink / raw)
To: zsh-users
zzapper wrote:
>
> I want to generalise top3 into top4,top5..etc
>
> function top3()
> {
> # description : vi 3 newest files
> file=$0
> num=${file//[[:alpha:]]/}
> gvim.exe -p $(l\s *(.om[1,$num])) &
> }
>
> In the above substitution I get the "number" by stripping out the alphas
> which is kind of a trick
>
> 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.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Substituting all but a trailing digit/number
2007-07-13 12:48 ` Peter Stephenson
@ 2007-07-13 13:22 ` zzapper
2007-07-13 13:36 ` Stephane Chazelas
0 siblings, 1 reply; 5+ messages in thread
From: zzapper @ 2007-07-13 13:22 UTC (permalink / raw)
To: zsh-users; +Cc: zsh-workers
Peter Stephenson <pws@csr.com> 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?
--
zzapper
http://www.rayninfo.co.uk/vimtips.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Substituting all but a trailing digit/number
2007-07-13 13:22 ` zzapper
@ 2007-07-13 13:36 ` Stephane Chazelas
2007-07-13 13:41 ` zzapper
0 siblings, 1 reply; 5+ messages in thread
From: Stephane Chazelas @ 2007-07-13 13:36 UTC (permalink / raw)
To: zzapper; +Cc: zsh-workers, zsh-users
On Fri, Jul 13, 2007 at 01:22:56PM +0000, zzapper wrote:
> Peter Stephenson <pws@csr.com> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Substituting all but a trailing digit/number
2007-07-13 13:36 ` Stephane Chazelas
@ 2007-07-13 13:41 ` zzapper
0 siblings, 0 replies; 5+ messages in thread
From: zzapper @ 2007-07-13 13:41 UTC (permalink / raw)
To: zsh-users; +Cc: zsh-workers
> Also, why are you using ls?
>
> Why not simply
>
> gvim -p *(.om[1,$num])
>
THNX Stephane
I can give no rational answer!!
--
zzapper
http://www.rayninfo.co.uk/vimtips.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-07-13 13:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-13 12:25 Substituting all but a trailing digit/number zzapper
2007-07-13 12:48 ` Peter Stephenson
2007-07-13 13:22 ` zzapper
2007-07-13 13:36 ` Stephane Chazelas
2007-07-13 13:41 ` zzapper
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).