Re: rename files in directory



aixdude@xxxxxxxxx wrote:

I have several thousand files like the following:

SolTrdBra_09062010_00_A0.pdf SolTrdBra_09062010_00_E0.pdf
SolTrdBra_09062010_00_I9.pdf SolTrdBra_09062010_00_MJ.pdf
SolTrdBra_09062010_00_B0.pdf SolTrdBra_09062010_00_ED.pdf
SolTrdBra_09062010_00_IM.pdf SolTrdBra_09062010_00_N0.pdf
SolTrdBra_09062010_00_BG.pdf SolTrdBra_09062010_00_G0.pdf
SolTrdBra_09062010_00_J1.pdf SolTrdBra_09062010_00_PP.pdf

I need to change the date portion of the file to look like the
following:
(add hyphen to date portion of file name)

SolTrdBra_09062010_00_J1.pdf SolTrdBra_09-06-2010_00_PP.pdf

Best way to do this?
Thanks in advance

#!/bin/bash

for f in Sol*.pdf
do
mv $f ${f::12}-${f:12:2}-${f:14}
done

exit

or with ksh93 another way:

#!/usr/bin/ksh

for f in Sol*.pdf
do
[[ $f == @-(*_??)@-(??)@-(????_*) ]] && \
mv $f ${.sh.match[1]}-${.sh.match[2]}-${.sh.match[3]}
done

exit

Mike.







--

echo "zvpunry.fpuvaqyre@xxxxxxxxxx" | tr A-Za-z N-ZA-Mn-za-m
.