Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename small part of multiple files in middle of name using Bash?

Tags:

I'd just like to change this

cc211_AMBER_13062012i.II  cc211_GROMOS_13062012i.II
cc211_CHARM_13062012i.II  cc211_OPLS_13062012i.II

to

cc211_AMBER_15062012i.II  cc211_GROMOS_15062012i.II
cc211_CHARM_15062012i.II  cc211_OPLS_15062012i.II

I tried,

find -name "*.13 *" | xargs rename ".13" ".15"

There is normally no space between the 3 and the second asterix, thats just makes it italics on from what I can see. Basically there's a lot of answers for what to do when it's at the end of the filename, where asterix seem to work, but here I can't make it work.

Anything you've got would make my life a lot easier!

Edit 1: Trial

-bash-4.1$ ls

cc211_AMBER_13062012.II  cc211_GROMOS_13062012.II
cc211_CHARM_13062012.II  cc211_OPLS_13062012.II

-bash-4.1$ rename 's/_13/_15/' cc*
-bash-4.1$ ls

cc211_AMBER_13062012.II  cc211_GROMOS_13062012.II
cc211_CHARM_13062012.II  cc211_OPLS_13062012.II 
like image 277
cc211 Avatar asked Jun 15 '12 15:06

cc211


1 Answers

How about this:

for i in *.II; do mv $i $(echo $i | sed 's/_13/_15/g'); done

This will replace _13 with _15 in all files with extension .II

More information on sed here.

like image 121
lobianco Avatar answered Sep 17 '22 15:09

lobianco