1

I have a number of files created by a program on our selling system that are produced in a format like the following:

CRY_SKI_14_EDI.LIS
CRY_SUM_14_EDI.LIS
THO_SKI_14_EDI.LIS
THO_LAK_14_EDI.LIS
CRY_SKI_IE_14_EDI.LIS

These files differ in numbers depending on the split of our product to different brandings. Is it possible to rename them all so that they read like the following:

CRY_SKI_14_EDI_DEMO.LIS
CRY_SUM_14_EDI_DEMO.LIS
THO_SKI_14_EDI_DEMO.LIS
THO_LAK_14_EDI_DEMO.LIS
CRY_SKI_IE_14_EDI_DEMO.LIS

I need the files to be correctly named prior to their FTP as a hardcoded file could potentially not exist due to the brand not being on sale and terminate the FTP which would prevent the other files following it from being transmitted to our FTP server.

Marcus Culver
  • 305
  • 1
  • 4
  • 8

1 Answers1

4

The OpenVMS rename command is more handy (imho) than the windows or unix variants, because it can bulk change chuncks of the full file name. Such as 'name', 'type' or (sub)directory.

For example:

$ rename *.dat *.old

That's great but it will not change within the chunks (components) like the name part requested here. For that, the classic DCL approach is a quick loop, either parsing directory output (Yuck!) or using F$SEARCH. For example:

$loop:
$ file = f$search("*EDI.LIS")
$ if file .eqs. "" then exit
$ name =  f$parse(file,,,"name","syntax_only") ! grab name component from full name
$ rename/log 'file' 'name'_demo                ! rename 'fills in the blanks'
$ goto loop

Personally I use PERL one-liners for this kind of work. (and I test with -le using 'print' instead of 'rename' first. :-)

$ perl -e "for (<*edi.lis>) { $old = $_; s/_edi/_edi_demo/; rename $old,$_}"

Enjoy! Hein

Hein
  • 1,453
  • 8
  • 8
  • Thanks Hein, Looks like i'm stuck doing it with the loop as PERL is not installed on our system however it works so problem solved. Thanks – Marcus Culver Oct 19 '13 at 14:36
  • Hein, Is it posible on the f$search to specify "/since" criteria? – Marcus Culver Oct 19 '13 at 14:41
  • Perl not installed? Fix that! When adding search criteria folks stoop to parsing directory output. You could add this line to the script: $ if f$cvt(f$file(file,"rdt")).lt."2013-10-00:-)" then goto loop", or ofcourse you probably want to pass that date/time that as 'p1'. – Hein Oct 19 '13 at 15:22
  • That's a .LTS. not .LT. using STRING compare for the date&time in the (default) COMPARISON output from F$CVTIME for the ABSOLUTE TIME format returned from F$FILE for the Revision Date attribute. – Hein Oct 19 '13 at 15:53
  • So you may want to have the additional line like `$ if f$cvt(f$file(file,"rdt")).lts. f$cvt(p1)` which enables you to pass in `TODAY`, `YESTERDAY` and usual (abbreviated) VMS dates like `16-oct`. And as you probably know `/since` is equivalent to `/since/created` and `cdt` while `rdt` is `/since/modified`. – user2116290 Oct 19 '13 at 17:14
  • I no longer have a system to try it out on, but I seem to recall that you can "append" to the globbed portion by doing something like `$ RENAME *.TXT *_OLD.TXT`...? – Hellion Oct 24 '13 at 19:09
  • Hellion... no can do. That would give: Error opening *_OLD.TMP; as output -RMS-F-FNM, error in file name. – Hein Oct 25 '13 at 15:20