Operating System - OpenVMS
1754014 Members
7547 Online
108811 Solutions
New Discussion юеВ

Re: VMS to UNIX script re writes

 
John Crump
Occasional Contributor

VMS to UNIX script re writes

Hello,

I am in the process of moving a system from OVMS to UNIX, and am re writing a number of DCL scripts. Can any one help with the following

$ xyz_file = f$search("dsa1:[John_extract.run]extract*.dat")
$ sh sym xyz_file
$ xyz_date1 = f$extract(5,4,xyz_file)
$ xyz_date2 = f$extract(9,2,xyz_file)
$ xyz_date3 = f$extract(11,2,xyz_file)
space = " "
$ xyz_date_sorted = f$string(xyz_date3+space+xyz_date2+space+xyz_date1)
$ sh sym xyz_date_sorted
$ xyz_date = ("xyz_date_sorted")

Is someone able to help with a suitable UNIX equivelent please?

Many Thanks
9 REPLIES 9
Robert Gezelter
Honored Contributor

Re: VMS to UNIX script re writes

John,

This segment of DCL is searching for filenames of the form "dsa1:[john_extract.run]extract*.dat". It is then extracting pieces of the filename to use in constructing a string. Looking at the character offsets, are you sure that this code is working as intended, or are there some pieces missing from the example?

- Bob Gezelter, http://www.rlgsc.com
John Crump
Occasional Contributor

Re: VMS to UNIX script re writes

Hello Bob

Thank you for your response.

You are quite correct. I have probobly broken the code in posting it as I need to protect the identity of the client. However the original code has worked well for several years.

Any sugestions on reproducing for UNIX?

Regards
Hein van den Heuvel
Honored Contributor

Re: VMS to UNIX script re writes

Think bigger, think perl

Do you just want to solve the string manipulation, or also the search?
What are you going to do with the string, once re-arranged?

I would use perl
- use its 'glob' function to find files
- use pattern matching, ot substr() to pick the names apart.
- build new string
- sort within the perl as needed
- ...

Starting example

perl -e 'while (){ m/extract(....)(..)(..)/; print "$3 $2 $1\n"}'

perl -e 'while (){ m/extract(....)(..)(..)/; push @list, "$3 $2 $1\n"} print reverse sort @list'

btw...

1) that DCL looks hoky... it needs an F$PARSE to get just the name into xyz_file

2) while porting, why not have the source deliver the files with the desirable names?

Enjoy, (but not too much. OpenVMS rules!)
Hein.



Derek Garson
Frequent Advisor

Re: VMS to UNIX script re writes

If you went with perl then you could migrate to perl while still on VMS, perhaps allowing more sane regression testing (rather than changing both your scripting language and your platform simultaneously).

If by Unix equivalent you mean that you intend to migrate from DCL to shell then you will have to indicate which shell.
Steven Schweda
Honored Contributor

Re: VMS to UNIX script re writes

> Is someone able to help with a suitable
> UNIX equivelent please?

> [...] indicate which shell.

Or at least which UNIX.

Also, the easiest way to do something on a
UNIX system may not look anything like the
way it was done on a VMS system.
Semi-mindless DCL -> shell-script translation
may be far fron the right approach.
James R. Ferguson
Acclaimed Contributor

Re: VMS to UNIX script re writes

Hi John:

...and since you posted this in multiple places, I'll add the text I did in HP-UX:

Please consider Hein's offering. Perl is platform agnostic and allows you to write extremely powerful code in a very straighforward fashion.

Even if you don't know Perl now, don't ignore the advice and the annotated example our friend has provided. Instead, profit from it and give Hein the credit he deserves.

Regards!

...JRF...
Craig A Berry
Honored Contributor

Re: VMS to UNIX script re writes

I would second (or third) the Perl recommendation, except that if you are really trying to disassemble file specs into their component parts I suggest using the File::Spec module that is included with Perl. It abstracts out the OS-specific syntax, so that, for example File::Spec->splitdir('[.foo.bar.baz]') on VMS will give you the same answer as File::Spec->splitdir('foo/bar/baz') on Unix.

There are also assorted Date::* modules if in fact you are really interested in dates rather filename components (can't tell from your example).
Derek Garson
Frequent Advisor

Re: VMS to UNIX script re writes

>Semi-mindless DCL -> shell-script translation may be far from the right approach.

warning: opinions and generalizations follow

There are trade-offs.

Mindless translation is more likely to give a correctly working result, get the result more quickly and with less effort.

Mindless translation is more likely to lead to a result that is less maintainable in the future and may lead to poor performance. Mindless translation also runs the risk of coming up against something that "can't" be translated.

If there is a *lot* of DCL to migrate then I would favour mindless translation.

If there is only a modest amount then I would favour abstracting what the procedures are attempting to achieve (or reading the associated system documentation, hah!) and re-engineering in the target environment.

But then I wouldn't favour any port from VMS to something else. (-:
Hoff
Honored Contributor

Re: VMS to UNIX script re writes

So you're looking for Unix expertise from a bunch of OpenVMS folks? Not the path I'd choose. Ask some Unix folks.

Do get yourself a bash manual (bash shell assumed) and look up substring expressions. There are various excellent bash guides and resources around.

Here's a basic bash replacement:

$ fodder=ab001122
$ echo ${fodder:6:2}${fodder:4:2}${fodder:2:2}
221100

Your DCL could be shorter, too.

The $ dollar here is the bash prompt, and not DCL.

Migrating to bash arguably leaves you in the same basic platform-level state as you have with DCL here, though bash is certainly rather more widespread than DCL, and an entirely capable and functional choice. Other good options include the aforementioned Perl, though I'd also look at php, Python and Ruby. Possibly Java. Move up the stack from the command shell, in other words.

And yes, there are folks around that are reasonably conversant in both OpenVMS and DCL, and in bash.

Stephen Hoffman
HoffmanLabs LLC