[BASH][HELP] Can someone help me write a script to rename files? - Programming On Unix

Users browsing this thread: 1 Guest(s)
z3bra
Grey Hair Nixers
Can be done with a for loop, using a bit of extracting with sed, and formatting with printf :)

Try to do it as an exercise !

extract the season number using sed, same for the episode. then use printf to create a new name for your file.

Then move the old name to the new name !

Code:
#!/bin/sh

for f in *.avi; do
    season=$(echo "$f" | sed 's/^.*Season \([0-9]*\).*$/\1/')
    episod=$(echo "$f" | sed 's/^.*E(\([0-9]*\).*$/\1/')
    name=$(printf "The_Mentalist_S%02dE%02d.avi" $season $episod)
    mv "$f" "$name"
done

exit 0


Messages In This Thread
RE: [BASH][HELP] Can someone help me write a script to rename files? - by z3bra - 06-09-2014, 07:42 AM