I need to batch rename bunch of files with id in name, adding a constant number to id
<id>-xxx.txt => <id+shift>-yyy.txt
Any ideas how to make it? Some awk maybe?
I need to batch rename bunch of files with id in name, adding a constant number to id
<id>-xxx.txt => <id+shift>-yyy.txt
Any ideas how to make it? Some awk maybe?
constant=42
for f in *.txt; do # choose your pattern as appropriate.
IFS='-.' read id suffix ext <<< "$f"
newname="$(( 10#$id + constant ))-yyy.$ext"
echo mv "$f" "$newname"
done
I added "10#" in the arithmetic expression to ensure the number is treated as base-10 even if it begins with a zero.
If this doesn't meet your needs, please provide more requirements in the question.
suffix
variable will contain whatever 'xxx' is. If there can be dashes and dots, I can provide alternatives, but this is exactly the kind of information you need to provide in the question. – glenn jackman Feb 05 '13 at 22:59