Question

I need to convert my bash script to OpenVMS, does any one know of an automatic converter or could help me manually ?

#!/bin/bash
#
# Convert input to .CNF
inputfile=$1

rm outfile;
for line in $(cat $inputfile | awk '{ print $1 }' | tr '\*' ' ' | grep 0041); do
if [ `cat $inputfile | grep ${line:0:11} | wc -l` -eq 100 ]; then
echo "?,    ?,    "${line:2:9}\* >> outfile;
elif [ `cat $inputfile | grep ${line:0:12} | wc -l` -eq 10 ]; then
echo "?,    ?,    "${line:2:10}\* >> outfile;
else
echo "?,    ?,    "${line:2} >> outfile;
fi;
#echo ${line:0:11};
done;
cat outfile | sort -u >> newoutfile;

The inputfile contains a list of numbers where I need to group them if there are 10 or 100 following numbers and otherwise print them normally. Example:

0041XYZ070690*
0041XYZ070691*
0041XYZ070692*
0041XYZ070693*
0041XYZ070694*
0041XYZ070695*
0041XYZ070696*
0041XYZ070697*
0041XYZ070698*
0041XYZ070699*
0041XYZ077778* 
0041XYZ077949* 
0041XYZ077950* 

becomes:

?,    ?,    0041XYZ07069*
?,    ?,    0041XYZ077778
?,    ?,    0041XYZ077949
?,    ?,    0041XYZ077950
Was it helpful?

Solution 4

Since GNV was very unstable I decided to use an external Linux Host which receives the output first by ssh then modifies it (with the script from above) and writes it back by sftp.

OTHER TIPS

Another option is to do this in Python

The author doesn't state which version of OpenVMS they are running

If it's an old version, (before 8.2) you can download the LD tool and install it. From memory it will require a reboot

8.2 onwards, the LD tool is fully integrated into OpenVMS

The LD tool will allow you to create and mount container file on OpenVMS

There are Python LD container files that have Python pre-installed on them, which means you don't have to install Python as such, just mount up the Python LD container file and run it (first you need to prepare the Python build by compiling, but this is all contained within the LD file, it will NOT install anything new onto the OpenVMS platform)

Once you have Python installed (within the LD container file), you can write your Python scripts and call them as necessary

Steps:

  1. If OpenVMS < 8.2; Download and install LD utility; reboot

(http://www.digiater.nl/lddriver.html)

  1. Download Python for OpenVMS container AND associated tools container (2 LD images).

(http://www.vmspython.org/doku.php?id=downloadandinstallationpython)

  1. Mount the LD container files as LD disks

  2. Compile Python (This is a once off)

  3. Run the Python startup (local to your process OR system wide, your choice)

  4. Invoke Python

I don't know of a converter, but you should be able to do this pretty easily in DCL. The tricky bits will be replacing the AWK processing with a few lines of logic processing - unless your system has GAWK available.

I don't know bash, but it's pretty clear what DCL commands you will need to use. I would suggest looking at the following in either DCL HELP (eg. $ help open) or the documentation set,

open

read

lexicals (in particular f$locate and f$extract)

if (then/else)

write

I suppose it depends how much DCL you already know. If you need to learn the basics, then the OpenVMS Users Manual is a good place to start http://h71000.www7.hp.com/doc/731final/6489/6489pro_contents.html (Chapters 2, 12,13 and 14 in partiuclar).

Alos http://dcl.openvms.org/ could be a handy resource - you may even find a converter there.

You maybe interested in GNV (GNU on OpenVMS) kit. http://h71000.www7.hp.com/opensource/gnv.html

It's free and it works. It supports bash, though not sure about awk. This way you should be able to use the same script on VMS.

Re-writing your script in DCL is very much possible too. There're a few ways to do that, apart from directly replicating bash steps with DCL "equivalents". You may let me know if you still need assistance with it.

Two years late I stumbled into this topic. Why would you not solve this problem entirely in AWK or PERL? Darn script weenies / one-trick ponies! The solution as used will not scale as it is an N-Square algorithm (and then some more)

For every data line present, the data file is read entirely (twice. By both cat and grep) That suggests there must not have been millions of rows.

That assumption allows us to simple accumulate the 'tens' and 'hundreds' counters in an array. Worst case (each record in an unique hundreds group) there would be as many elements in each array as input records. More likely the total is much less than half. The Awk script below should work on OpenVMS and is tested only with provided dataset. For a 'real' solution, it would be good to know whether the input is sorted, might have dups, and so on.

Enjoy, Hein.

$!  DCL ... is is not. Just AWK
$ gawk /VAR=(INPUTFILE='p1') /INPUT=SYS$INPUT NL:
BEGIN {
   while ((getline < INPUTFILE) > 0) {
     lines++
     if ($0 !~ /0041/)  continue
     tens[substr($0,1,12)]++
     huns[substr($0,1,11)]++
   }
   print lines i" lines read from " INPUTFILE
   close (INPUTFILE)
   while ((getline < INPUTFILE) > 0) {
     if ($0 !~ /0041/) continue
     sub(/\*/,"",$0)
     k =  substr($0,1,11)
     x =  huns[k]
     if (x == -1) continue
     if (x == 100) {
        print "?, " k "**"
        huns[k] = -1
        continue
        }
     k = substr($0,1,12)
     x = tens[k]
     if (x == -1) continue
     if (x == 10) {
        print "?, " k "*"
        tens[k] = -1
        continue
        }
     print "?, " $0
     }
}
$ EXIT
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top