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

Users browsing this thread: 1 Guest(s)
neo1691
Members
Great, I will work on it. and then compare it with the code you have given. I haven't clicked on the show button yet!
(06-09-2014, 07:42 AM)z3bra Wrote: #!/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

I have to give up with sed.
I mean I looked up into it, but I clearly need to understand more about it.
Can you explain those regex to me?

Edit: To be more clear I was stuck to that part of sed, where I thought that how can I extract text from sed, where you can replace text using sed.
I mean I was trying to do this in sed:

sed -n 's/[[:digit:]]/WhatToPutHere/2p'
Knowing that the second digit is the episode number.

I would have used 3p where the episode number entered double digits.


Messages In This Thread
RE: [BASH][HELP] Can someone help me write a script to rename files? - by neo1691 - 06-09-2014, 01:38 PM