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?

3
  • Look at man rename; you are using the wrong syntax for the version of rename on your OS. Also see unix.stackexchange.com/a/238862/135943
    – Wildcard
    Commented May 23, 2016 at 23:31
  • You're only matching a single digit after Galaxy. You need to use [0-9]+ to match any number of digits. And you shouldn't have spaces around -.
    – Barmar
    Commented May 23, 2016 at 23:43
  • 2
    You need prename, not rename (rename is only prename on Debian and derivatives). Commented May 23, 2016 at 23:47

1 Answer 1

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*
2
  • 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
    Commented May 24, 2016 at 0:33
  • I've changed the pattern to match everything after the ].
    – Barmar
    Commented May 24, 2016 at 0:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .