[NTLUG:Discuss] batch file rename

Dennis Kaptain dkaptain at yahoo.com.mx
Tue Sep 9 11:17:47 CDT 2014



Looking more at the big picture, I don't see how you are renaming the files.
Try something like this

for FILE in `ls -1 *.mp3`
do
NEWNAME=`sed sed s/CCC-\([0-9]+\)-\([0-9]+\)-\([0-9]+\).mp3/\3\1\2\.mp3/`
mv $FILE $NEWNAME
done


El Martes, 9 de septiembre, 2014 8:18:25, Robinson Tryon <bishop.robinson at gmail.com> escribió:
 

>
>
>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
>
>
>_______________________________________________
>http://www.ntlug.org/mailman/listinfo/discuss
>
>
>


More information about the Discuss mailing list