
Eu tenho vários arquivos como:
bla.super.lol.S01E03.omg.bbq.mp4
bla.super.lol.S01E04.omg.bbq.mp4
bla.super.lol.s03e12.omg.bbq.mp4
Eu preciso renomear todos eles como:
s01e03.mp4
s01e04.mp4
s03e12.mp4
Eu tentei fazer isso, for file in *; do mv $file ${file%%\.omg*}; done
mas remove apenas parte depois de S01E01, não antes, por favor, ajude
Responder1
Com rename
( prename
):
rename -n 's/^bla\.super\.lol\.[sS](\d+)[eE](\d+)\..*(\.mp4$)/s$1e$2$3/' *.mp4
-n
faz o teste, se você estiver satisfeito com a possível renomeação, basta remover -n
para permitir que a renomeação real ocorra:
rename 's/^bla\.super\.lol\.[sS](\d+)[eE](\d+)\..*(\.mp4$)/s$1e$2$3/' *.mp4
Exemplo:
$ ls -1
bla.super.lol.S01E03.omg.bbq.mp4
bla.super.lol.S01E04.omg.bbq.mp4
bla.super.lol.s03e12.omg.bbq.mp4
$ rename -n 's/^bla\.super\.lol\.[sS](\d+)[eE](\d+)\..*(\.mp4$)/s$1e$2$3/' *.mp4
bla.super.lol.S01E03.omg.bbq.mp4 renamed as s01e03.mp4
bla.super.lol.S01E04.omg.bbq.mp4 renamed as s01e04.mp4
bla.super.lol.s03e12.omg.bbq.mp4 renamed as s03e12.mp4
Responder2
#!/bin/bash
IFS="\n" # Handle files with spaces in the names
for file in *.mp4; do
newfile="${file/bla.super.lol./}" # Strip the prefix you don't want
newfile="${newfile/S/s}" # Change the first S to an s
newfile="${newfile/E/e}" # Change the first E to an e
newfile="${newfile.%omg.bbq*}" # Strip the suffix you don't want
newfile="${newfile}.mp4}" # Tack on the file extension again
done
if [[ "$file" == "$newfile" ]]; then
echo "Not renaming $file - no change decreed."
elif [[ -f "$newfile" ]]; then
echo "Not renaming $file - $newfile already exists."
else
mv -- "$file" "$newfile" # Make the change
fi
Responder3
Mantenha simples..
rename 's/.*\.(\w+)\.omg\..*mp4$/\L$1.mp4/' *.mp4
Exemplo:
$ echo 'bla.super.lol.S01E03.omg.bbq.mp4' | perl -pe 's/.*\.(\w+)\.omg\..*mp4$/\L$1.mp4/'
s01e03.mp4