1

In one directory I have many files which look like this:

Galaxy100-[0025-CL3.single.bed].bed

and I would like to change it to:

0025-CL3.single.bed

I tried this rename 's/Galaxy[0-9] - \[//' *, but it did not change anything.

How is possible to rename these files?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

2

Your regular expression doesn't match the pattern in your filename. To match at least one digit, you need to use [0-9]+ (you can also use \d to match digits); your pattern will only match 1 digit. Your example filename doesn't have spaces around -, but you have them in the pattern. And you're not doing anything to remove the ] at the end. Try:

rename 's/Galaxy\d+-\[(.*)\].*/$1/' Galaxy*
Barmar
  • 9,927
  • In CentOS 6 it did not work, but it work almost in Ubuntu 14.04 and I got 0025-CL3.single.bed.bed. How is it possible to remove the file extension? – user977828 May 24 '16 at 00:33
  • I've changed the pattern to match everything after the ]. – Barmar May 24 '16 at 00:36