Author
Topic: Renaming/editing a specific part of a file (Read 1190 times)

I am trying to edit rather a lot of files in different directories and finding it such a bore doing it in PyRename.Filenames such as 'Clear.and.Present.Danger.1994.1080p.BluRay.x264.YIFY.mp4'I want to change it so that the year is in '()' but some of the filenames already have the year in brackets or theres a duplicate but in a different format such as '.avi' or '.mkv'

But I know there's going to be more involved and it may end up as a script to execute.I've got 'Linux Pocket Guide' but it goes nowhere near the stuff I need to do, so I am going to hopefully soon get more books to help me.

This will match all files containing .19??. and .20??. It will then print "mv (original file name) (file name with brackets around the year).So if you do this command and so "> out.sh" , you can then do "chmod a+x out.sh; ./out.sh" to execute the commands.(you could stick this last but on the same line as the find, but this way you can look at out.sh and make sure it's going to do what you expect)

Print the original filename ($0) with a an "mv" command and no newline.

Quote

gsub(".(19|20)...",".(&).");

Replace any occurrence of "." followed by 19 or 20, followed by any two digits, followed by a dot, with the original match, surrounded by ".( )."(the deliberate "bug" here is ".(19|20)..." should probably be "\\.(19|20)..\\." - someone can test this .. )

Thanks for the help there Mark & MP.I've not got round to executing the command as I'm renaming the files, editing out other spurious rubbish first.Also, just a thought, remembering back in '91-'92 while on the programming course. I'm sure I remember something about being able to differentiate between numbers and alphabet, so isn't there some sort of 'wildcard' for numbers, separate to alphabet. Can't we use that in some way?

Just tested it on a couple of files and it produced this result with one of the files;mv ./Monty Python's Life of Brian 1979 720p DTS multisub GER HUN HighCode.mkv ./Monty Python's Life of Brian.(1979)..(20p ).TS multisub GER HUN HighCode.mkv