I have a couple files with the name
(a).1
(a).2
...
(a).100
Since a lot of processing tools don't really like (
and )
in the filename I thought it best to rename them to a different name. I googled for renaming files and found the wonderful tool rename
where I can feed a regular expression. Okay let's try this:
$ rename -v s/\(a\)/b/ \(a\).*
(a).1 renamed as (b).1
(a).2 renamed as (b).2
(a).3 renamed as (b).3
Hmm not what I expected. After a bit of googling I found that \(
\)
is a grouping operator. Which sort of makes sense since I did not escape the (
)
in the command.
I solved my renaming problem by using the .
character that matches all types of values:
rename -v s/.b./b/ \(b\).*
This solution is not really nice. So how do I match (
and )
in Bash/Linux/Unix Regex?
LANG=en_US.UTF-8
environment. Maybe cygwin does some weird mangling with the input. I was able to solve this by putting the regex into quotes:rename -v 's/\(a\)/a/' \(b\).*
.rename [options] expression replacement file..
you've got the expression and the replacement but not the file. Looks after options (e.g. -v) there are 3 mandatory parameters there, separated by spaces. But your rename command only has 2 of them. i'll check my rename version (- uppercase V)$ rename -V<ENTER> rename from util-linux 2.24.2
rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E *perlexpr*]*|*perlexpr* [ *files* ]
. So we have two different versions.