On our Series 937 I need a routine that will delete all but the last five files in a group that begins with certain values and have a certain pattern to the file names.
Example: We keep old copies of our PowerHouse dictionaries, but only need the last five. I can not do it by date like other groups of files, since it does not get changed everyday. Sometimes we'll go weeks, even months before we make a change.
I have a routine for other groups of files (interface files) that get created every day and keep only the last 31 days. This is done very easily with VESOFT’s MPEX by simply checking the create date. I was wondering if anyone has a routine either in JCL or MPEX that will keep the last 5 instances of these files. The two file-naming conventions are PT###### and PL######. The ###### represent MMDDHH (month, day, hour).
A wide range of solutions emerged from HP 3000 experts, veterans and consultants.
Francois Desrochers replies
How about doing a LISTF and use PRINT to select all but the last 5 into another file (PTPURGE):
You could massage PTPURGE and turn each line into a PURGE. It has been a while since I used MPEX, but maybe it has an indirect file function e.g. %PURGE ^PTPURGE.
Of course MPEX has such a function. Vladimir Volokh of VESOFT supplied an elegant solution involving a circular file, a feature added to MPE/iX more than 15 years back.
First, build an MPE circular file (to do this, look at HELP BUILD ALL). The nearly 1,000 lines that will follow include an explanation of the CIR parameter. We use logfiles below in our example.
BUILD V; CIR; DISC=5
FILE V, OLD
LISTF LOG####, 6;*V
(MPE's asterisk, by the way, can be used in about 19 different ways, Vladimir adds.)
Your result in V can be your last five names. Now you purge, using MPEX -- because purging something minus something is an MPEX-only function. (Using the caret sign is a way to signal all the files mentioned in the file V.)
There are other solutions available that don't require a third-party gem like MPEX.
This is easy enough to do. Here are the steps:
Do a listf into a file 'foo'
Set 'count' = end-of-file count
Set 'index' to 1
Set 'maxindex' to 'count' - 5
Increment 'index' by 1
If 'index' < 'maxindex' then
Loop to read 'foo'
The exact syntax is up to you and MPE.
Barry Lake adds
Very simple if you're willing to use the Posix shell. If this needs to be done with CI scripting, it's certainly possible, but way more complicated. Someone else may chime in with an "entry point" command file to do this in "pure" MPE. But here's the shell method:
So... move the last 5 out of the way, delete whatever's left, then move the 5 back into place.