Page 1 of 1

[Bash/Linux] Help with Rename script

Posted: August 18th, 2011, 1:36 pm
by dashy
Hi all,

Newb here - I'm looking for help coding an automatic renamer script which will remove the source/codec/group from commonly downloaded tv files. For example, I'd like the script to change:
minute.to.win.it.s02e38.hdtv.xvid-qcf.avi TO minute.to.win.it.s02e38.avi
House.S07E22.HDTV.x264-DIMENSION.mkv TO House.S07E22.mkv

Basically this applies only to TV shows so all I want it to search for "hdtv", and remove that until the period before the file extension. Any tips? Thanks in advance!

Re: [Bash/Linux] Help with Rename script

Posted: August 18th, 2011, 2:34 pm
by Mar2zz
Use sed to replace stuff.

pseudocode:
#$1 is inputfile (or directory)

filename=$(basename $1)
extension=${filename##*.}
newname=echo $filename | sed 's/.xvid.*\|.x264.*//g'
mv $filename $newname.$extension

Re: [Bash/Linux] Help with Rename script

Posted: August 18th, 2011, 10:00 pm
by dashy
Thanks for your help :)