Visit Our UNIX and Linux User Community

Renaming list of files with version numbers

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming list of files with version numbers
# 1  
Old 07-30-2009
Renaming list of files with version numbers

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.

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 -> 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.
# 2  
Old 07-30-2009
yes, but it will be somehow require long script. did you already start with your project?
# 3  
Old 07-30-2009
Originally Posted by try2shell
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
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.

# 4  
Old 07-31-2009
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.


Previous Thread | Next Thread
Test Your Knowledge in Computers #208
Difficulty: Medium
Open Shortest Path First (OSPF) was designed as an exterior gateway protocol (EGP) for use in an autonomous systems such as a local area network (LAN).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. Shell Programming and Scripting

Renaming file that has multiple numbers as filename

Hi I have a file with filename as "partition-setup-and-ipl.vtcmd.76217657132.9721536798" Now i need to move this file as "partition-setup-and-ipl.vtcmd.76217657132.9721536798_org" i tried with # ls | grep -E "partition-setup-and-ipl.vtcmd.+"... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. Shell Programming and Scripting

How to sort version numbers?

I would like to know how to sort version numbers, using bash or perl. I would like to sort file names that are program names with version numbers and extensions, such as hello-0.2.3.tar.gz and hello-0.10.3.tar.gz. Version numbers of computer programs do not comply with the mathematical rule... (3 Replies)
Discussion started by: LessNux
3 Replies

4. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

5. Shell Programming and Scripting

Finding consecutive numbers in version names on a txt file

Hi all. I have a directory which contains files that can be versioned. All the files are named according to a pattern like this: TEXTSTRING1-001.EXTENSION TEXTSTRING2-001.EXTENSION TEXTSTRING3-001.EXTENSION ... TEXTSTRINGn-001.EXTENSION If a file is versioned, a file called ... (10 Replies)
Discussion started by: fox1212
10 Replies

6. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

7. Shell Programming and Scripting

Remove version numbers from package lists

I just upgraded my laptop from Fedora 13 to 14, and normally, before I do the upgrade (Fresh install) I run an rpm command to make a list of all the packages I have installed, but without the version and architectures specified, so that I can just feed that list to yum after the upgrade to... (2 Replies)
Discussion started by: Tsuroerusu
2 Replies

8. Shell Programming and Scripting

script to find filenames with latest version and for all seq. numbers in a day

Hi, We have a requirement to find the set of filenames from the group of files in a specified folder based on (i) version number (ii) sequence number such that, for any given sequence number in a day only the latest version filenames have to indentified. Below is the format of... (4 Replies)
Discussion started by: Deepakbabu
4 Replies

9. UNIX for Dummies Questions & Answers

Comparing Version Numbers

Hi There! Apologies if this has been asked previously but I couldn't find the answer I was hoping for. Basically, all I want to do is compare the OS X version against the version that I require in my script. So I'm retrieving the OS version using defaults read, but how can I compare this... (10 Replies)
Discussion started by: davewg
10 Replies

10. Shell Programming and Scripting

renaming files with numbers

I have files of the sort dhfmovie1.txt dfhmovie2.txt and want to rename them to dhfmovie01.txt dhfmovie02.txt the files are in a directory with many other files, I only need to do this for files with 1-9 in the name. can anyone help me with the correct sed/mv script? thanks (2 Replies)
Discussion started by: pacat
2 Replies

Featured Tech Videos