I have a list of files (thousands of them) like this:
/path/2010 - filename.txt
/path/2011 - another file name.txt
Always following this pattern: #### - string.txt
I need to change them to look like this:
/path/filename (2010).txt
/path/another file name (2011).txt
How can I do this quickly with bash, shell, terminal, etc.?
I'd prefer to add this as a comment, but I'm not yet allowed to.
I asked a similar question and received a number of helpful answers over here:
https://unix.stackexchange.com/questions/37355/recursively-rename-subdirectories-that-match-a-regex
Perhaps one of those solutions can be adapted to suit you needs.
I know you didn't tag it with
zsh
but you did sayshell
. Anyway here's how to do it with thezmv
function inzsh
:Remove
-n
when you're happy with the output.-v
makeszmv
verbose.-w
implicitly makes a group of each wildcard.Try
rename
command:-n
(--no-act) option is for preview.Remove
-n
to perform substitution.Untested.
Remove the
echo
once the generatedmv
commands look right.