You are not logged in.
Pages: 1
Hi,
I was organizing my music library and found some folders like this:
1974NameOfAlbum/
2002AnotherName/
I know it's possible to rename using mv, however I don't know how to insert "\ -\ " in the 5th character to have something like
1964 - NameOfAlbum/
2002 - AnotherName/
I guess it can be done with shellscript using rename, mv or cut. (but I don't know how )
Last edited by julio (2009-07-12 01:36:47)
Offline
ls -1|sed -e "s/^\(.*\)hello\(.*\)$/mv '\1hello\2''\1 - hello\2'/"|bash
Something similar, it renames in the $pwd the *hello* folders to * - hello*
The problem is i don't know your rules. Is the date 4 character in every case ? It can be solved with sed easily.
Hope this helps
Offline
Thanks for the fast answer.. I'll test now
Yes, all dates have 4 characters.
Offline
ls -1|sed -e "s/^\(.*\)hello\(.*\)$/mv '\1hello\2''\1 - hello\2'/"|bash
Your code was just missing a space between '\1hello\2' and '\1 - hello\2'. Really helped me.
I made:
ls -1|sed -e "s/^\(....\)\(.*\)$/mv '\1\2' '\1 - \2'/"|bash
(that gets 4 chars from the start and add the ' - ' after them)
And it solved my problem.
But what if I've already started renaming the folders one by one (with mv)?
It would turn "1964 - NameOfAlbum/" into "1964 - - NameOfAlbum/"...
Anyway. The biggest problem is already SOLVED.
Thanks for the help.
Offline
You can do it with for;done;do cycle too, but i like sed very very much
No problem.
Offline
Pages: 1