Renaming list of files with version numbers

Hi,
I have a need to rename a list of files with a suffix .v1, .v2, v3 etc. and would like to keep a maximum of 6 versions.

example:
I have abc.sql in my current dir. and as part of a successful completion of another script I want to move abc.sql -> abc.sql.v1.

When I run the original script again, I want to move
abc.sql.v1 -> abc.sql.v2 and the current abc.sql -> abc.sql.v1

The third time...abc.sql.v2 -> abc.sql.v3 and so on....

I would like to keep 6 versions of the files (abc.sql.v6)

Is there an easy way using scripting/awk to achieve this?

Thanks in advance.

yes, but it will be somehow require long script. did you already start with your project?

I don't think this is clear.
After you have moved abc.sql.v1 to abc.sql.v2, how can you move abc.sql to abc.sql.v1 ?
abc.sql.v1 is gone; it has been moved to abc.sql.v2.
And in the same way, abc.sql was long gone, because it had been moved to abc.sql.v1.

tyler_durden

Sorry, if I wasn't clear...

All I am trying is to preserve the 6 oldest copies of the file (abc.sql).

So, when I run the script for the first time an output file abc.sql is generated and there is no other versions of it. After running the file (abc.sql - from the original script), at the end I want to move abc.sql -> abc.sql.v1 (at which point I will have no use for abc.sql.v1 - except for reference).

When I run the script a second time, it will generate another abc.sql and after all other processing I would like to move abc.sql.v1 -> abc.sql.v2 and the current abc.sql to abc.sql.v1....and so on.

I would like to keep 6 versions of abc.sql (up to abc.sql.v6) after which I can overwrite the oldest versions.

Hope this helps.

Thanks.