How to remove files with different release number?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove files with different release number?
# 1  
Old 04-06-2013
How to remove files with different release number?

Hi,

I have many data files formatted in "dataName-versionNumber-releaseNumber.location.data" in a directory of Linux CentOS 6.2 system.

My directory could have following files for example:

graphicData1-1.2.3-2.0.0.mel.au.data
graphicData1-1.2.3-2.0.1.mel.au.data
graphicData1-1.2.3-2.0.2.mel.au.data

All the files have the same version number 1.2.3, but different release number such as 2.0.0, 2.0.1, 2.0.1. I need to keep the highest release number such as graphicData1-1.2.3-2.0.2.mel.au.data and to delete files with smaller release number, such as graphicData1-1.2.3-2.0.0.mel.au.data and graphicData1-1.2.3-2.0.1.mel.au.data.

How can I do it in a bash script?

Thank you.

Kind regards.
# 2  
Old 04-07-2013
Quote:
Originally Posted by hce
Hi,

I have many data files formatted in "dataName-versionNumber-releaseNumber.location.data" in a directory of Linux CentOS 6.2 system.

My directory could have following files for example:

graphicData1-1.2.3-2.0.0.mel.au.data
graphicData1-1.2.3-2.0.1.mel.au.data
graphicData1-1.2.3-2.0.2.mel.au.data

All the files have the same version number 1.2.3, but different release number such as 2.0.0, 2.0.1, 2.0.1. I need to keep the highest release number such as graphicData1-1.2.3-2.0.2.mel.au.data and to delete files with smaller release number, such as graphicData1-1.2.3-2.0.0.mel.au.data and graphicData1-1.2.3-2.0.1.mel.au.data.

How can I do it in a bash script?

Thank you.

Kind regards.
In the format:
Code:
dataName-versionNumber-releaseNumber.location.data

you say that "." is the separator between releaseNumber and location, and it is also the separator between location and data.

I assume that the ".data" is a constant.

Is location always "mel.au" or does it vary between files? If it varies between files, will it be a constant for a given dataName and versionNumber pair, or can you have multiple locations for a given dataName and versionNumber pair?

If there are multiple locations for any dataName and versionNumber pair, and "." is the separator between releaseNumber and location and also appears in both releaseNumber and location, how do we know where releaseNumber ends and location starts? Does any alphabetic character ever appear in a releaseNumber? Does any location ever contain a numeric character? Does releaseNumber always contain two "." characters (as in 2.0.0)? Does location always contain one "." character (as in "mel.au")?
# 3  
Old 04-07-2013
If any of Don Cragun's questions apply, the following will not necessarily work:
Code:
$ ls | sort -r | sort -u -t- -k2,2
graphicData1-1.2.3-2.0.2.mel.au.data

# 4  
Old 04-07-2013
Quote:
Originally Posted by RudiC
If any of Don Cragun's questions apply, the following will not necessarily work:
Code:
$ ls | sort -r | sort -u -t- -k2,2
graphicData1-1.2.3-2.0.2.mel.au.data

If any of the three numeric components of the releaseNumber could be more than a single digit (e.g., 2.0.10), the sort will have to be much more complex than this. I was also under the impression that there were likely to be multiple dataName values in files in the directory (which would require using -k1,2 instead of -k2,2). If there are multiple dataNames or varying numbers of periods in versionNumbers or releaseNumbers, I'm not even sure that this can be done by sort without some pre-processing by something like awk to generate a consistent sort key at the start of each line.

I think the question is deceptively simple for what may be a much more complex problem. We need more details on the actual filename format.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 04-07-2013
@Don Cragun: Absolutely! I started fiddling around with awk, thinking about the more-than-one-digit (sub-)release numbers, and it became awkward. What I proposed above is just dealing with the simple sample posted in #1.
# 6  
Old 04-07-2013
Quote:
Originally Posted by RudiC
@Don Cragun: Absolutely! I started fiddling around with awk, thinking about the more-than-one-digit (sub-)release numbers, and it became awkward. What I proposed above is just dealing with the simple sample posted in #1.
The ".data" is a constant. The release numbers only contains numeric characters, no alphabetic characters. It is separated by "." character, but it could be two, or tree or four, such as 2.0, or 2.0.0, or 2.0.0.1.

The location always contain one "." character. The dataName is a single string, the dataName, versionNumber and releaseNumber are delimeted by "-", but after the releaseNumber, the "." is delimeted between the releaseNumber and localtion. The localtion can be treated as constant as well.

Thanks RudiC and Don Cragun.
# 7  
Old 04-07-2013
Quote:
Originally Posted by hce
The ".data" is a constant. The release numbers only contains numeric characters, no alphabetic characters. It is separated by "." character, but it could be two, or tree or four, such as 2.0, or 2.0.0, or 2.0.0.1.

The location always contain one "." character. The dataName is a single string, the dataName, versionNumber and releaseNumber are delimeted by "-", but after the releaseNumber, the "." is delimeted between the releaseNumber and localtion. The localtion can be treated as constant as well.

Thanks RudiC and Don Cragun.
OK. That helps, but one more point is crucial. Will any part of the versionNumber or releaseNumber ever be more than one digit (such as 2.1.10, 1.11, or 3.0.12.5)?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove string between number and character

hello ! I have to remove string between a number and set of characters. For example, 35818 -stress - - -stress - - - - - - DB-3754 44412 caul kid notify DB-3747 54432 roberto -, notify DB-3725 55522 aws _ _int _ _classified 2_a _a 2_m _m 2_classified 2_search... (7 Replies)
Discussion started by: ManoharMa
7 Replies

2. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies

3. Solaris

Remove number in file name

Hi , i have a file name with date and time append like test_SEC_AES_V1_T03_2016031404306 i want to remove the date and time after _ and rename to current date and time,can any one please let me know as i tried some options but din't help:( Thanks, Please use code tags as required... (10 Replies)
Discussion started by: caba_jones
10 Replies

4. Shell Programming and Scripting

Remove trailing number

I have some strings such as ABC1 ABC2 TYFASDD12 They will only have letters and numbers. In each case I want to remove the last digit? The lengths will vary. So a hard coded substr won't work. What do I do? if it doesn't end in a number, I don't want to remove any characters. (6 Replies)
Discussion started by: guessingo
6 Replies

5. UNIX for Dummies Questions & Answers

Remove char if not a number

I need to write a BASH script that takes a 2 character string and removes the second character if it is not a digit e.g. If the string is numberical value >9 e.g. string1 = '34' then leave string1 = '34'. However if the string is <10 e.g. string1 = '3X' then remove the second char (which... (7 Replies)
Discussion started by: millsy5
7 Replies

6. Shell Programming and Scripting

Remove last number from a file

Hi, I need to delete last number ( i.e 126) from the file which has below contents. ABC DEF "XYZ" 2837.5 3852.5 126 ABC DEF "XYZ" 2897.5 3852.5 126 ABC DEF "XYZ" 2957.5 3852.5 126 Please help. Thanks in advance. (17 Replies)
Discussion started by: gujrathinr
17 Replies

7. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

8. Shell Programming and Scripting

script for remove descending order number

hi all i want to remove some descending order number example : 1 100 200 135.00 Gk_wirs 1 1 100 200 136.00 Gk_wirs 50 1 110 210 138.00 Gk_wirs 60 1 100 200 136.00 Gk_wirs 57 ----> how to remove... (6 Replies)
Discussion started by: nithyanandan
6 Replies

9. Shell Programming and Scripting

remove the number from the String

I have string like 20091112_File_Name_40301.txt and i have a set of files in the directory with the same format . i want to write the ksh to rename the file ..... like eg 20091112_File_Name_40301.txt to File_Name.txt 20091112_abc_2343.txt to abc.txt... (6 Replies)
Discussion started by: gavemani
6 Replies

10. AIX

Remove APAR number from aix 5.3

Hi... Can i remove one APAR number from aix5.3.. If it is possible how to do.. Thanks.. (3 Replies)
Discussion started by: sumathi.k
3 Replies
Login or Register to Ask a Question