I’m trying to rename several different files in bash.
How to rename for example temp_1 to temp_01 until 09 (temp_9 to temp_09)?
I used sed but somehow didn’t work.
I tried with this:
for i in temp_?.txt;
do
j=echo $i | sed 's/[^0-9]*/0[^0-9]*/g';
mv "$i" "$j";
done
Try to modify your
sedcommand to something likeThat will do the work for your example case.
Your command doesn’t work because when you are trying to reference the matched string you actually don’t: it’s done with
&(for the whole match) or numbered references.