[NTLUG:Discuss] batch file rename

Robinson Tryon bishop.robinson at gmail.com
Tue Sep 9 08:17:40 CDT 2014


On Mon, Sep 8, 2014 at 7:09 PM, Bobby Wrenn <bobby at wrennest.com> wrote:
> It's been a while since I have fiddled with regular expressions and I need a
> little help.
>
> I have a single directory with many files with names in the format
> "CCC-01-10-2012.mp3". In need to rename each file into the format
> "20120110.mp3".
> I tried;
> ls *mp3 | sed s/CCC-\([0-9]+\)-\([0-9]+\)-\([0-9]+\).mp3/\3\1\2\.mp3/ | sh
> but that returns "not found" for each entry.
>
> What am I missing?

IIRC you need to escape the plus sign as \+, at least in the GNU sed.
Also, I'm not sure that piping the output to sh is going to have the
desired effect.

Here are some useful examples/notes:
https://stackoverflow.com/questions/17137566/rename-multiple-files-with-sed
https://stackoverflow.com/questions/2372719/using-sed-to-mass-rename-files/2372739#2372739

HTH,
--R

-- 
Robinson Tryon
QA Engineer - The Document Foundation
LibreOffice Community Outreach Herald
qubit at libreoffice.org



More information about the Discuss mailing list