Wednesday, May 15, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 492  / 3 Years ago, mon, july 5, 2021, 3:06:39

How to rename


sluno-20201027-call-metroua-status.mp4
sluno-20201103-call-deriva.mp4
sluno-20201103-call-metroua-status.mp4
sluno-20201105-call-makrocz.mp4
sluno-20201105-call-metroua-testcall.mp4
sluno-20201105-call-sluno-ggtabak.mp4
sluno-20201110-call-makrocz.mp4
sluno-20201110-call-metroua-status.mp4
sluno-20201110-call-sluno-utccz.mp4

to


sluno-call-metroua-status-20201027.mp4
sluno-call-deriva-20201103.mp4
sluno-call-metroua-status-20201103.mp4
sluno-call-makrocz-20201105.mp4
...

Simply move date / string on position 7-14 to the end of the name of file.


Thanks.


More From » bash

 Answers
4

mmv works well for uncomplicated file renaming.


mmv '*-*-*-*.mp4' '#1-#3-#4-#2.mp4'

It may also be helpful to have some more reference points to be sure not to change the name on something else, especially where there may be other files in the same directory.


mmv 'sluno-[0-9]*-call-[a-z]*.mp4' 'sluno-call-#3#4-#1#2.mp4'
^ ^ ^ ^
1 2 3 4

sluno-20201027-call-metroua-status.mp4
^------- ^-------------
1 2 3 4


If I were to do it with the bare minimum, mv and bash I would go with a for-loop and bash builtin BRE matching.


for i in *.mp4; do 
[[ $i =~ ^sluno-(.*)-call-(.*).mp4 ]] &&
mv -- "$i" "sluno-call-${BASH_REMATCH[2]}-${BASH_REMATCH[1]}.mp4";
done

[#2182] Tuesday, July 6, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ersoggles

Total Points: 69
Total Questions: 111
Total Answers: 111

Location: Vanuatu
Member since Sun, Oct 2, 2022
2 Years ago
ersoggles questions
;