Needed script for the version file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Needed script for the version file
Prev   Next
# 1  
Old 12-17-2012
Needed script for the version file

I need some help with the logic and syntax for a shell script (ksh) that will search a directory and look for similar files and save only the 5 versions. The version number is in the file name.
However, the files are of varying name lengths and may have 1 or many files, with no limit to the number of files.
the input file
Code:
A_14122012.txt
A_15122012.txt
A_16122012.txt
A_17122012.txt

the output should contain the present and past one file

Code:
A_16122012.txt
A_17122012.txt

i used the below code please sugest the correct script

Code:
for file in `ls *.txt | sort -r | nawk -F"[2012|.]" '{if(_[$1]<2){print $0;_[$1]++}}' `
do
    echo $file
done

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 12-17-2012 at 10:19 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy a file from directroy/ prior version to the directory/ new version

How to copy a file from directroy/ prior version to the directory/ new version automatically. (4 Replies)
Discussion started by: roy1912
4 Replies

2. Shell Programming and Scripting

Needed script to FTP a File and generate a quality checksum file

hi all i want a script to FTP a file and should generate a quality checksum file means when I FTP a file from one server to another server it should generate a QC file which should contain timestamp,no.of records in that file Thanks in advance saikumar (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

3. Shell Programming and Scripting

Script for download file with version

Hi, Need Shell script to download the file with version or date from internet Filename will be as Eg:File-2.3.1.zip Filename will keep on changing for every 4months as File-2.3.2 or File 2.4 Thanks, Anil (4 Replies)
Discussion started by: Anil2312
4 Replies

4. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

5. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

6. Shell Programming and Scripting

Help needed with script to verify the version of BIND

I have tried thought of using instfix -ivqc | grep BIND , but this did not return the result I was looking for; it seem to list out the the different patches that had been applied to BIND. I'm actually looking for overall version, like you'd get when checking the OS level for instance. (1 Reply)
Discussion started by: sport
1 Replies

7. Programming

Why a shared version is needed

Trying to make a library and get this error : *** Warning: This library needs some functionality provided by -lming32. *** I have the capability to make that library automatically link in when *** you link to this library. But I can only do this if you have a *** shared version of the... (1 Reply)
Discussion started by: hirosima
1 Replies
Login or Register to Ask a Question