0

Is possible to rename and substitute on fly with bash? for example i have

  VTS_01_1.VOB  VTS_01_2.VOB  VTS_01_3.VOB

I want to rename for use in mencoder with

movie_1.avi movie_2.avi,etc..

I know how to substitute VTS,but not VOB.

for i in  VTS_01_[1-4]*B;do echo ${i/VTS_0?_?.VOB/Movie}.avi;done

give me

Movie.avi
Movie.avi
Movie.avi
Movie.avi

i want

Movie_1.avi
Movie_2.avi
Movie_3.avi
Movie_4.avi
  • 1
    Feel free to use perlexpr with rename command . – Cyrus Oct 4 '14 at 21:43
3

You can do it in two steps e.g. first remove the extension, then substitute the VTS_01 prefix:

$ for i in VTS_01_[1-4]*B; do b="${i%.VOB}"; echo "${b/VTS_01/Movie}.avi"; done
Movie_1.avi
Movie_2.avi
Movie_3.avi
3

Use rename program. It uses perl expression. How ever here we have no complex expression.

In this case you can use this:

rename VTS_01 movie VTS_01*VOB
  • Be aware that there are at least two different programs called rename, and they use very different syntax for expressing how to map the original names to new names. – chepner Oct 5 '14 at 22:12
2

Why don't you use python? Something like

$ ipython
In [1]: import os
In [2]: all_files = os.listdir(".")
In [3]: for filename in all_files:
In [4]:     newname = 'Movie' + filename[6:9] + 'avi'
In [5]:     os.rename(filename, newname)

should solve your problem.

-1

BIngo!

for i in  VTS_01_[1-4]*B;do echo mv $i  "$(echo $i|sed 's/VTS/Movie/g;s/VOB/avi/g')";done

Is more useful with commands like mencoder,etc

  • 2
    You should really accept steeldriver's answer; it showed you the structure to use and is cleaner (no additional process called). – jasonwryan Oct 5 '14 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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