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)?
What about a set of meaningful samples so we don't have to dream them up ourselves?
Thanks RudiC, please see following files, Files with the highest release number such as graphicData1-1.2.3-2.0.2.mel.au.data and graphicData2-1.0-1.2.mel.au.data should be kept. And files of graphicData1-1.2.3-2.0.0.mel.au.data, graphicData1-1.2.3-2.0.1.mel.au.data, graphicData2-1.0-1.0.mel.au.data and graphicData2-1.0-1.1.mel.au.data should be removed.
You did not provide
- four field release numbers
- two digit release fields
Try this concoction of commands 'n pipes, for a set of sample files that I dreamed up it worked as desired:
Use it as a starting point for further refinement from your side if it does not fit your needs. Or, provide a really really representative set of samples!
You did not provide
- four field release numbers
- two digit release fields
Try this concoction of commands 'n pipes, for a set of sample files that I dreamed up it worked as desired:
Use it as a starting point for further refinement from your side if it does not fit your needs. Or, provide a really really representative set of samples!
That is very close. Actually your first statement can also display all the files I need to keep:
$ ls
graphicData1-1.2.3-2.0.0.mel.au.data graphicData2-1.0-1.0.mel.au.data
graphicData1-1.2.3-2.0.1.mel.au.data graphicData2-1.0-1.1.mel.au.data
graphicData1-1.2.3-2.0.2.mel.au.data graphicData2-1.0-1.2.mel.au.data
graphicData1-1.2.3-2.0.3.mel.au.data
How can I display all the files I need to delete instead I need to keep? Then I might be able to use following command if the following command syntax can be fixed:
a) assuming your shell is bash (in your Linux system), use the "extended pattern matching operator" !(pattern-list).
b) use grep -v to eliminate the files found from the total file list.
c) ...
z) use your creativity/fantasy/imagination to dream up other solutions!
Here is a much more verbose awk script that I think does what you want.
As always, if you're using a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of awk.
This script was tested using the Korn shell and bash; it should work with any POSIX conforming shell. It will work with one or more components in the versionNumber and releaseNumber fields (as long as all of the components are entirely numeric values with each component consisting of no more than 5 digits. It will not work if any dataName contains a hyphen character (-).
If you don't want the play by play report of what will be kept and what will be removed, delete the lines in blue above. Once you have convinced yourself that it will remove the files you want removed, delete the echo in red above.
Enjoy...
These 2 Users Gave Thanks to Don Cragun For This Post:
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)
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)
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)
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)
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)
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)
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)
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)
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)