Reputation: 68
I have 500 files with name as file_0.yuv , file_1.yuv, file_2.yuv .....file_499.yuv
I want to rename the file with adding 500 into the file number in each file name
For example:
file_0.yuv -> file_500.yuv
file_1.yuv -> file_501.yuv
file_2.yuv -> file_502.yuv
...
file_499.yuv -> file_999.yuv
I tried to use :
for i in `seq 0 499`; do mv file_$i.yuv file_$i+500.yuv; done
But that does not serve the purpose as file name come to : file_0+500.yuv
Can any one suggest me the correct command here ?
UPDATE:
I am using bash script.
Upvotes: 1
Views: 99
Reputation: 15246
You can probably also use sequences, at the possible loss of some portability.
for s in {0..499}; do mv file_$i.yuv file_$((i+500)).yuv; done
Upvotes: 0
Reputation: 9855
If your shell is bash
you can use $(( ... ))
for arithmetic.
for i in `seq 0 499`; do mv file_$i.yuv file_$((i+500)).yuv; done
Instead of using backticks `foo`
you should prefer to use $(foo)
for i in $(seq 0 499); do mv file_$i.yuv file_$((i+500)).yuv; done
Upvotes: 4