January 26th, 2010, 11:09 PM
Pre-pend to file REGEX
Heres a fairly simple one, ive gotten close and i have a system where about ~3 regexes will get me what i need, but i yearn for a one step solution. I had though this should work but i think im overlooking something simple... any advice?
rename -n 's/\(.\)*.mp4$/prePend$1\.mp4/' *.mp4
with my goal being to turn any file.mp4 into prePendfile.mp4, bearing in mind it should be able to include ! , ' - numbers and words
January 27th, 2010, 06:57 AM
You're overcomplicating things. If you just want to add to the start of the filename, there's no need to match anything, capture it in $1 and re-add it again. You also don't need to have .mp4 in your match, since you're only applying your 'rename' to *.mp4 in the first place. Either of these should do it:
The second of those demonstrates that the argument to 'rename' doesn't have to be a regexp.
rename -n 's/^/prePend/' *.mp4
rename -n '$_="prePend$_"' *.mp4