0

I have a some filenames that I would like to (ideally manually) rename using a bash script which is run every hour using crontab.

The Filenames are as such:

SeriesName v01 (Year) (Other irrelevant Data).ext
SeriesName v02 (Year) (Other irrelevant Data).ext
SeriesName v03 (Year) (Other irrelevant Data).ext
and so on

I would like to rename them to this :

SeriesName 01 (Year) (Other irrelevant Data).ext
SeriesName 02 (Year) (Other irrelevant Data).ext
SeriesName 03 (Year) (Other irrelevant Data).ext
and so on

The files are sometimes in subfolders How would I do this? I know that I can use find -type f -name '*.ext' to find all Files that match the extension I want, but how can I remove the v?

WorldTeacher
  • 93
  • 1
  • 10
  • 1
    Have a look at the rename cmd in bash: rename [options] ... There are loads of examples online. – FreudianSlip Mar 17 '22 at 17:39
  • 1
    also could look at string manipulation [here](https://stackoverflow.com/questions/1469849/how-to-split-one-string-into-multiple-strings-separated-by-at-least-one-space-in) and [here](https://tldp.org/LDP/abs/html/string-manipulation.html) – julian Mar 17 '22 at 17:41
  • for file in * ; do mv "$file" "${file/ v/ }"; done << will do the job at least in the current directory – FreudianSlip Mar 17 '22 at 17:49
  • @FreudianSlip I tried your script an it seems to work pretty well, but I've noticed something: when it renames, it removes the whitespace between SeriesName and 01, what can i do to add it back? – WorldTeacher Mar 17 '22 at 18:05
  • just remove the space in this : `"${file/ v/ }"` , should be like: `"${file/v/}"` . – User123 Mar 17 '22 at 18:09
  • @User123 that seems to work, but only if there's a single `v` in the file, if any other `v` are present, only the first one will get removed – WorldTeacher Mar 17 '22 at 18:12
  • As per the sample input provided, the only logic to rename the files seems to be : removing the v from filename ... – User123 Mar 17 '22 at 18:27
  • yes, but when I do that, and the `v` is in the `SeriesName`, the `v` won't be removed later on. Only the first `v` will be removed. Can I somehow start the code looking from the end of the filename? – WorldTeacher Mar 17 '22 at 18:29
  • @User123 @FreudianSlip I figured out how to avoid the Filename, I replaced `/v/` with `/v0/0`, not I just need to find out, wether or not I can loop this with v1 to v9 – WorldTeacher Mar 17 '22 at 18:59

0 Answers0