I am receiving video files with different names but the final 8 characters of all are numbers (also different every time). This is the pattern of the file name:custom text 00030402.aviI have to make file name looks like this:00\:03\:04\:02So my question is how to rename the last 8 characters and preserve them to achieve this pattern.
Rename the last 8 characters in filename
bash;rename;bash script;patterns
Using rename (the one from perl sometimes called prename, not from util-linux):rename 's/(\d{2})(\d{2})(\d{2})(\d{2})/$1:$2:$3:$4/'  *.aviThis would rename a filename like custom text 00030402.avi to custom text 00:03:04:02.avi.If you backslashes in the filename (before the :), say:rename 's/(\d{2})(\d{2})(\d{2})(\d{2})/$1\\:$2\\:$3\\:$4/' *.aviIn order to remove the custom text from the filenames, say:rename 's/.* (\d{2})(\d{2})(\d{2})(\d{2})(.*)/$1\\:$2\\:$3\\:$4$5/' *.avi