6

I have various files that are names

"type_featAtype_featB"

and

"type_featAtype_featC"

I need that all

"type_featA"

are replaced with

"START"

so the new names of the folders would be called

"STARTtype_featB"

and

STARTtype_featC"

.

I have been looking at the rename function here and here

However, not all of my files have the same suffix, in fact they all have different suffixes as indicated in the example.

Thus, I am looking for insight on how to use a command to replace just a part of the file name, as indicated above in one folder where each file had a unique suffix. Thank you

Thank you in advance for any help.

2
  • How does replacing type_featA with START transform type_featAtype_featB into STARTtypeDM_featB?
    – devnull
    Oct 23, 2013 at 14:17
  • Human error: See edited question
    – owwoow14
    Oct 23, 2013 at 14:20

3 Answers 3

11

A more cryptic option would be to use SED - I suppose that you would choose to do this if you had no access to the perl rename function (which I admit is more concise, and more clear):

ls * | sed -e 'p;s/^type_featA/START/' | xargs -n2 mv

1
  • 1
    I like this cryptic version ;-)
    – oHo
    Oct 23, 2013 at 14:48
6

Assuming you have the rename utility that is a part of perl distribution, you could say:

rename 's/^type_featA/START/' *

to achieve the desired result.

2

The devnull's answer is correct. You can even write:

rename 's/^type_featA/START/' my_folder/type_featA*

This command line is perfect on Debian and other derived distributions.

But, other distributions may use a different tool as for Fedora, RedHat and CentOS. In this second case the right command line is:

rename type_featA START my_folder/type_featA*

This second tool will replace only the first type_featA occurrence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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