Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I just discovered zmv this morning.

To test it i have created a few files.

test1.txt test2.txt test3.txt

I'm trying to rename them with zmv I'd like to get this output:

test-1.txt test-2.txt test-3.txt

when I try to use wildcards I get an error message:

zmv '(*)([0-9]{1,})(.txt)' '$1-$2$3'
zmv: error: number of wildcards in each pattern must match

Am i doing something wrong (answer has to be yes :) )

share|improve this question
    
If the first parameter is a regular expression and it is greedy by default, try ([^0-9]*) as the first part maybe. –  Oliver Salzburg Mar 14 '12 at 12:04
    
What zsh version? Do you have zmv aliased? –  Gilles Mar 14 '12 at 22:38
    
zsh 4.3.9, autoload -U zmv, alias zmv="noglob zmv -W" –  Yannick Schall Mar 14 '12 at 23:26
    
@OliverSalzburg: It's not that it's greedy by default (backtracking takes care of what I think you're trying to fix). The problem is that * is applying to (, since he wrote * instead of .*. That's probably why zmv thinks there aren't enough capturing groups. –  Peter Cordes Mar 1 at 9:45

2 Answers 2

Do you only want to add a - to the filename? Try it like this:

zmv -n 'test(*).txt' 'test-${1}.txt'

The -n switch shows you what would happen without really performing any action.

share|improve this answer
    
Tried just that, but I get the same error message. I'm running zsh 4.3.9 on osx. not sure if it changes anything. –  Yannick Schall Mar 14 '12 at 12:56

If the first arg is supposed to be a regex, the problem is probably that you used * instead of .*. (* is the 0-or-more operator, . matches any single character).

So the first paren probably got taken literally as the arg of the * operator, instead of opening a capture group.

Try out http://www.regexr.com/ for an interactive regex tutorial / tester / builder thing.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.