I use xmbc to view my tv shows. Before I began using xmbc, I batch downloaded the first few seasons of "Bleach". What can I say, I'm an anime fan ;-). These are named: "bleachxx.mp4" where xx is the episode number in respect to the whole series, not to the season. so "bleach21.mp4" is the 1st episode of the second season and 21st overall. The files themselves are, however, divided into their own season folders.
I know you can use the "rename" command to batch rename files. After much tinkering with it using this guide: http://tips.webdesign10.com/how-to-bulk-rename-files-in-linux-in-the-terminal I got this command:
rename -n 's/.*(\d{2}).*$/Bleach S0XE$1/' *
The problem is that the command will rename all the files into "Bleach S0XExx" but because the files have the overall file numbers, bleach52.mp4 --> 'Bleach S03E52.mp4' when there obviously aren't 52 episodes in season 3.
I would like to know, then, if there is any way to apply mathematical operations to the file renaming. This would solve the problem as I could subtract The number of episodes in the previous seasons by the overall number and essentially get the season number.
Example: If there are 20 episodes in season 1, then 25-20=5 so the 25th episode is the 5th of season 2 and renaming would carry out as normal.
So, is there anyway to change the values of renaming by applying math operations?
P.S. I'm sorry for the long explanation but I wasn't sure how to or if my question would be clear without it.