On Sat, 16 Aug 2008, David C. Rankin wrote:- While you've already had some answers, here's a few other tips.
The problem is that I cannot get sed to allow substitution of a
value contained in the sed expression. So far, I can do:
for i in $(ls); do
ORIG_FNAME=$i NEW_FNAME=$(echo $i | sed -e 's/^100/`date +%Y%m%d`/') ^ ^
These aren't the same as using double-quotes. Bash won't do expansion or execution within single quoted strings.
Also, there's no need for the "echo | sed" combination. You could use: DATE=$(date +%Y%m%s) for ORIG_FNAME in * do if [ "${ORIG_FNAME::3}" == "100" ] # check first three characters of $ORIG_FNAME then NEW_FNAME=${DATE}${ORIG_FNAME:3} else continue # skip this file fi # if a file with the new name exists, skip it, else rename # [ ! -e "${NEW_FNAME}" ] && mv "${ORIG_FNAME}" "${NEW_FNAME}" Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-P2 @ ~100Mnodes RC5-72 @ ~15Mkeys SUSE 10.1 32 | | openSUSE 10.3 32b | openSUSE 11.0 32b | openSUSE 10.2 64b | openSUSE 10.3 64b | openSUSE 11.0 64b RISC OS 3.6 | TOS 4.02 | openSUSE 10.3 PPC | RISC OS 3.11 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org