Here is one I put together in KSH before we really got to rolling in Cloverleaf (I’d probably do it in TCL now):
A few notes, the comment is ‘eGate to cloverleaf’ but it is a basic two item CSV file. the default was %default%,<value>, so we would grab and set that as necessary. This also created the name as a copy with .tbl as the extension, regardless of the previous extension. I wrote this rather quickly with limited comments as it was a initially a throwaway script for converting mass tables. I need to update it since we use it for csvs now when updating larger tables. It doesn’t take long even on tables with a few thousand lines, though TCL would probably parse it faster. Note this is on RHEL and I can’t guarantee POSIX compliance on the script, though I don’t think there’s much to be non-compliant on.
#!/bin/ksh
#Table conversion from eGate to cloverleaf.
tableSet=””
clTable=””
clTableName=””
egTableName=””
defVal=””
default=””
userName=”$(who am i | awk -F’ ‘ ‘{print $1}’)”
datetime=”$(date +’%B %d, %Y %r EDT’)”
prologue=”# Translation lookup table\n\
#\n \
prologue\n \
who: ${userName}\n \
date: ${datetime}\n \
outname: output\n \
inname: input\n \
bidir: 0\n \
type: tbl\n \
version: 6.0\n \
end_prologue”
if [[ ! -f $1 ]]; then
echo “$1 is not a valid file”
else
egTableName=$1
clTableName=$(echo $egTableName | sed -E ‘s/(.*\.)(.*)/\1tbl/’)
if grep -q “%default%” $egTableName; then
defVal=$(grep “%default%” $egTableName | awk -F’,’ ‘{print $2}’)
fi
default=”#\ndflt_passthrough=0\ndflt=${defVal}\ndflt_encoded=false”
clTable=”${prologue}\n${default}”
while read line; do
input=”$(echo ${line} | cut -d’,’ -f1)”
output=”$(echo ${line} | cut -d’,’ -f2)”
firstChar=”$(echo ${line} | cut -b 1)”
if [[ ( “${firstChar}” != “#” ) && ( “${firstChar}” != “%” ) ]]; then
clTable=”${clTable}\n#\n${input}\n${output}\nencoded=0,0″
fi
done < “${egTableName}”
printf “${clTable}” > “${clTableName}”
fi