Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change part of file name grep or rename

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.

like image 662
owwoow14 Avatar asked Dec 06 '22 04:12

owwoow14


2 Answers

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

like image 154
MrSynAckSter Avatar answered Apr 28 '23 23:04

MrSynAckSter


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.

like image 42
devnull Avatar answered Apr 29 '23 00:04

devnull