Have a problem with a simple awk script that continues to give me the classic "field $() is not correct" and the kicker is that this worked fine under ksh on HP, but under bash and AIX it fails - help??
script:
VARLVL_ID="^M^L"
VLENGTH=0
FTP_AWK='
BEGIN{
VARLVL_ID=v;
VLENGTH=l;
VLIFOUND=0;
}{
if ( substr($0,1,VLENGTH) == VARLVL_ID && VLIFOUND == 0 ) {
$PRINT "";
VLIFOUND=1;
}
else if ( substr($0,1,VLENGTH) == VARLVL_ID && VLIFOUND == 1 )
$PRINT "^L";
else if ( substr($0,1,2) == "^M^M" )
$PRINT "";
else
$PRINT $0;
}'
inside of bash script:
cat ${FILENAME} | awk -v v="$VARLVL_ID" -v l="$VLENGTH" "${FTP_AWK}" > ${NEWFILENAME}.ftp
script:
VARLVL_ID="^M^L"
VLENGTH=0
FTP_AWK='
BEGIN{
VARLVL_ID=v;
VLENGTH=l;
VLIFOUND=0;
}{
if ( substr($0,1,VLENGTH) == VARLVL_ID && VLIFOUND == 0 ) {
$PRINT "";
VLIFOUND=1;
}
else if ( substr($0,1,VLENGTH) == VARLVL_ID && VLIFOUND == 1 )
$PRINT "^L";
else if ( substr($0,1,2) == "^M^M" )
$PRINT "";
else
$PRINT $0;
}'
inside of bash script:
cat ${FILENAME} | awk -v v="$VARLVL_ID" -v l="$VLENGTH" "${FTP_AWK}" > ${NEWFILENAME}.ftp