1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Rep Power

    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
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Shanghai, An tSín
    Rep Power
    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:
    rename -n 's/^/prePend/' *.mp4
    rename -n '$_="prePend$_"' *.mp4
    The second of those demonstrates that the argument to 'rename' doesn't have to be a regexp.

IMN logo majestic logo threadwatch logo seochat tools logo