![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| shell script for comparing 2 files | prashanth.spl | UNIX for Dummies Questions & Answers | 2 | 06-20-2008 11:09 AM |
| Random files do not FTP in the shell script | RLatham20 | Shell Programming and Scripting | 1 | 06-29-2006 01:07 PM |
| How to manage multiple versions of a set of shell and SQL script utilities | DennisB | Shell Programming and Scripting | 2 | 06-23-2004 09:13 AM |
| Purge files, keep 3 versions of last 4 days | blt123 | Shell Programming and Scripting | 7 | 10-28-2002 09:49 PM |
| Moving .html files while preserving hyperlink integrity? | Buddy123 | UNIX for Dummies Questions & Answers | 1 | 12-21-2000 03:59 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
shell script preserving last 2 versions of files
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 last two 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. I am not sure that using the find command for date/timestamp is a good idea because these are adhoc files that get created.
For example: Directory may have files like below apps_V01.xml betarelease_V01.xml betarelease_V02.xml betarelease_V03.xml test_V01.xml test_V02.xml test_V03.xml test_V04.xml testing_V01.xml testing_V(..).xml Representing all numbers 2 -99 testing_V100.xml The result should be: apps_V01.xml betarelease_V02.xml betarelease_V03.xml test_V03.xml test_V04.xml testing_V99.xml testing_V100.xml I thought about putting the listing into a text file and then substringing the names using awk, but don't know how I would handle the number of similar files. My thought is to output the listing to a file, read the file until it reaches a new file creating an array of files and then save the last two in the array. Then read for the next set of files. But again, not sure how to do that. A problem also occurs when I only have 1 version of a file. I welcome any sed, awk or ksh commands. I don't know enough about Perl or any other language in order to do this. Some help would be greatly appreciated. I have searched more than 300 postings and not coming up with anything fairly close to what I need to accomplish. Last edited by synergy_texas; 10-28-2008 at 06:56 PM.. |
| Bookmarks |
| Tags |
| removing multiple files directory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|