The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-28-2008
synergy_texas synergy_texas is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 19
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0