Вопрос

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

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.

Другие советы

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

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top