Skip to content
Advertisement

how to change a part in multiple filenames from 1 to 01?

I have lots of files in a directory.

Example:

 "/data/2014/file300.data.20141231.MC.9.vgf.img"

here 9 represent the hour and change from 1 to 24,the date also change. the hours are represented .1. .2. .3. .4. .... .9. I want to replace this part(only this part) in the file name with .01. .02. .03. .04. .... .09. and do not touch any other number in the file name.

so .1. become .01. and so on

Advertisement

Answer

Try this with Larry Wall’s rename to replace .MC. by .MC.0:

rename 's/.MC./.MC.0/' /data/2014/*.img
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement