Python: DCL Conversion to Python

This script is specific to operations moving from VMS to Linux, which requires migrating DCL scripts to Python scripts.

 

#!/bin/bash

# processDCL.sh

# Glenn Norman 2018

# Uncomment these two lines to prompt for a script name.
# This script assumes the DCL script is a plain text file.
# echo "Please specify a DCL script: "
# read filename

# Uncomment the line below to run in debug
# (automatic file selection) mode.
filename=DBMS_OOS_MEDICAID_RPT_POSTED.txt
echo 1

# Remove unused head and tail material from a DCL script
if [ -e $filename ]; then
echo 2
# trim off the head matter
awk '/CSESSION/,0' $filename > file1
echo 3
# trim off the trailing matter
sed '/HALT/q' file1 > file2
echo 4

else
echo "Please enter a valid file name."
echo 5
fi

echo 6

# get rid of $!
sed s/\$\!//g file2 > file3
echo 7

# get rid of leading spaces
sed -e 's/^[[:space:]]*//' file3 > file4
echo 8

# prefix every line
sed -e 's/^/xx/' file4 > file5
echo 8.5

# split the lines
sed -e 's/!/\n!/g' file5 > file6
echo 9

# correct the line order
sed 'N;s/\(.*\)\n\(.*\)/\2\n\1/' file6 > file7
echo 10

# remove all spaces from the end of lines
sed -i 's/[ \t]*$//' file7
echo 11

# turn all lines that start with a bang into expect lines
sed s/!/child.expect\(\'/g file7 > file8
echo 12

# now add sendline to all lines that start with xx
sed -e s/xx/child.sendline\(\'/g file8 > file9
echo 13


# add the ') suffix to each line
sed s/$/\'\)/g file9 > file10
echo 15

# fix extra line returns
tr -d '\015' < file10 > file11

# TODO: Transform first line to child = child.spawn ...

# TODO: Add head material: shebang, include and any other 
# necessary lines.

# TODO: Add cleanup routine to delete temp files.

# TODO: Review output file for any further needed transformations.

# TODO: Update final filename to original name + timestamp + .py.