Hi,
don't know if it's usefull in this particular case but here's a script I use on Linux to convert fixed recordsize ASCII files to unload files. I guess if you make it a ksh script it will work on AIX to.
Code:
#!/bin/bash
if [ ! $# -ge 1 ]; then
echo "`basename $0`: missing file argument"
echo " Usage: `basename $0` FILE [[COLUMN] ...] [DELIMITER]"
exit 1
fi
tmp="${HOME}/.`basename $0`.tmp"
[ -f "${tmp}" ] && rm $tmp
touch $tmp
dlm="|"
cnt=0
for j in $@
do
let cnt=${cnt}+1
if [ $cnt -eq 1 ]; then
if [ "${j}" = "-" ]; then
file=$j
elif [ -f "${j}" ]; then
file=$j
else
echo "Error: file '`pwd`/${j}' not exists, exit program!"
exit 1
fi
else
chk=`echo $j | awk '{print ($0 !~ /[^0-9]/) ? 0 : 1}'`
if [ $chk -eq 1 ]; then
if [ $cnt -eq $# ]; then
dlm=`echo $j | \
awk '{print ($0 ~ /^[^0-9a-fA-F]$/) ? $0 : "\\\"}'`
if [ "${dlm}" = "\\" ]; then
echo "Error: '${j}' is invalid delimiter, exit program!"
exit 1
fi
else
echo "Error: '${j}' is no column number, exit program!"
exit 1
fi
else
echo $j >> $tmp
fi
fi
done
awk 'BEGIN {
FS = ""
split(ARGV[2], inp, "=")
while(getline a[++n] < inp[2] > 0) {}
}
{
str = ""
for(i = 1; i <= (l = length($0)); i++)
{
str = str sprintf("%s", substr($0, i, 1))
for(j in a)
if(a[j] == i)
{
sub(/ +$/, "", str)
str = str d
}
if(i == a[n])
break
}
for(j in a)
if(a[j] > l)
{
sub(/ +$/, "", str)
str = str d
}
print str
}' d=$dlm v=$tmp $file
rm $tmp
Use this script like:
Code:
$ mkunl sourcefile 6 10 15 21 27 31 36 42 48 52 57 63
I would use this script to make an unload file first and then use awk (with the
-F "|" option to redefine the fieldseperator) to further process the fieldvalues.
Regards,
Hans