Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top