zsh-users
 help / color / mirror / code / Atom feed
* pad numbers
@ 2008-11-15 18:08 fREW Schmidt
  2008-11-15 18:33 ` Wayne Davison
  0 siblings, 1 reply; 7+ messages in thread
From: fREW Schmidt @ 2008-11-15 18:08 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 387 bytes --]

Hello friends!

I have a problem that I am sure numerous people have faced before, but I
couldn't find a lot of help for on Google.  I have a bunch of files named
like this:
01
02
03
...
10
11
12
...
101
102
103

How can I easily rename all the files so that they will be like this:
001
002
003
...
010
011
012
...
101
102
103 ( hundreds stay the same)


Thanks for any tips.
-- 

-fREW

[-- Attachment #2: Type: text/html, Size: 510 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pad numbers
  2008-11-15 18:08 pad numbers fREW Schmidt
@ 2008-11-15 18:33 ` Wayne Davison
  2008-11-15 18:36   ` fREW Schmidt
  0 siblings, 1 reply; 7+ messages in thread
From: Wayne Davison @ 2008-11-15 18:33 UTC (permalink / raw)
  To: fREW Schmidt; +Cc: zsh-users

One way to 0-pad the numbers 01..99 without touching the 100..NNN files
is to use zmv:

autoload zmv
noglob zmv -W ?? 0??

I like the zmv -W command so much I make it simpler by having this in
my .zshrc:

autoload zmv
alias mmv='noglob zmv -W'

That way I can do the above will this trivial command:

mmv ?? 0??

..wayne..


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pad numbers
  2008-11-15 18:33 ` Wayne Davison
@ 2008-11-15 18:36   ` fREW Schmidt
  2008-11-15 18:40     ` Mikael Magnusson
  2008-11-15 19:04     ` Phil Pennock
  0 siblings, 2 replies; 7+ messages in thread
From: fREW Schmidt @ 2008-11-15 18:36 UTC (permalink / raw)
  To: Wayne Davison; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 143 bytes --]

Ah shoot, I forgot to mention that the files are actually named like this
01 - foo bar.baz

maybe
noglob zmv -W ??\ (*) 0??\ \1

?

-- 

-fREW

[-- Attachment #2: Type: text/html, Size: 178 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pad numbers
  2008-11-15 18:36   ` fREW Schmidt
@ 2008-11-15 18:40     ` Mikael Magnusson
  2008-11-15 18:53       ` fREW Schmidt
  2008-11-15 19:04     ` Phil Pennock
  1 sibling, 1 reply; 7+ messages in thread
From: Mikael Magnusson @ 2008-11-15 18:40 UTC (permalink / raw)
  To: fREW Schmidt; +Cc: Wayne Davison, zsh-users

2008/11/15 fREW Schmidt <frioux@gmail.com>:
> Ah shoot, I forgot to mention that the files are actually named like this
> 01 - foo bar.baz
>
> maybe
> noglob zmv -W ??\ (*) 0??\ \1

The point of -W is you can do
noglob zmv -W ??\ * 0??\ *

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pad numbers
  2008-11-15 18:40     ` Mikael Magnusson
@ 2008-11-15 18:53       ` fREW Schmidt
  0 siblings, 0 replies; 7+ messages in thread
From: fREW Schmidt @ 2008-11-15 18:53 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Wayne Davison, zsh-users

[-- Attachment #1: Type: text/plain, Size: 388 bytes --]

On Sat, Nov 15, 2008 at 12:40 PM, Mikael Magnusson <mikachu@gmail.com>wrote:

> 2008/11/15 fREW Schmidt <frioux@gmail.com>:
> > Ah shoot, I forgot to mention that the files are actually named like this
> > 01 - foo bar.baz
> >
> > maybe
> > noglob zmv -W ??\ (*) 0??\ \1
>
> The point of -W is you can do
> noglob zmv -W ??\ * 0??\ *
>


Oh man, that's so cool!  (It worked great)

-fREW

[-- Attachment #2: Type: text/html, Size: 797 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pad numbers
  2008-11-15 18:36   ` fREW Schmidt
  2008-11-15 18:40     ` Mikael Magnusson
@ 2008-11-15 19:04     ` Phil Pennock
  2008-11-15 19:39       ` Stephane Chazelas
  1 sibling, 1 reply; 7+ messages in thread
From: Phil Pennock @ 2008-11-15 19:04 UTC (permalink / raw)
  To: fREW Schmidt; +Cc: zsh-users

On 2008-11-15 at 12:36 -0600, fREW Schmidt wrote:
> Ah shoot, I forgot to mention that the files are actually named like this
> 01 - foo bar.baz

If you want to specify the length more manually than the simple method:

% mkdir T && cd T
% touch '01 - Foo' '02 - Bar' '03 - Baz' '100 - Fred' '2000 - Long'

naive:
% zmv '([[:digit:]]##)(*)' '${(l:3::0:)1}$2'
% ls
000 - Long 001 - Foo  002 - Bar  003 - Baz  100 - Fred

Note that this has truncated the 2000 entry because I have explicitly
specified that $1 should be fit within a field three characters wide,
left-padded with digit 0.  See zshexpn(1), Parameter Expansion Flags.

Recreating the original files, then:
% zmv '([[:digit:]]|[[:digit:]][[:digit:]])([^[:digit:]]*)' '${(l:3::0:)1}$2'
% ls
001 - Foo   002 - Bar   003 - Baz   100 - Fred  2000 - Long

You might prefer [0-9] to [[:digit:]].

Perhaps you prefer the zmv -W approach.  ;-)

-Phil


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pad numbers
  2008-11-15 19:04     ` Phil Pennock
@ 2008-11-15 19:39       ` Stephane Chazelas
  0 siblings, 0 replies; 7+ messages in thread
From: Stephane Chazelas @ 2008-11-15 19:39 UTC (permalink / raw)
  To: fREW Schmidt, zsh-users

On Sat, Nov 15, 2008 at 11:04:25AM -0800, Phil Pennock wrote:
[...]
> Recreating the original files, then:
> % zmv '([[:digit:]]|[[:digit:]][[:digit:]])([^[:digit:]]*)' '${(l:3::0:)1}$2'
> % ls
> 001 - Foo   002 - Bar   003 - Baz   100 - Fred  2000 - Long

Or:

zmv -n '(<0-999>)(*)' '${(l:3::0:)1}$2'

Which BTW changes "00002 - X" to "002 - X".

-- 
Stéphane


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-11-15 19:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-15 18:08 pad numbers fREW Schmidt
2008-11-15 18:33 ` Wayne Davison
2008-11-15 18:36   ` fREW Schmidt
2008-11-15 18:40     ` Mikael Magnusson
2008-11-15 18:53       ` fREW Schmidt
2008-11-15 19:04     ` Phil Pennock
2008-11-15 19:39       ` Stephane Chazelas

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).