I wrote a script on HPUX 11.11 to turn a Decimal subnet mask (255.255.254.0) to hex 0xfffffe00 (subset of a bigger script). It works great on the HPUX systems but on the freebsd box the awk is not seperating the fields properly. I tried to google for a solution and seaching these forums i am just hoping someone can help. And if anyone knows how i can add the printf lines directly to the end of the awk statements that would be groovy.
I am unsure of the awk version HPUX uses but the freeBSD version is:
awk version 20050424 (FreeBSD), I would prefer not to use nawk or gawk.
#!/bin/sh
echo "Enter Subnet mask:"
read MASK
OCT1=$(echo $MASK|awk '{FS=".";print $1}')
OCT2=$(echo $MASK|awk '{FS=".";print $2}')
OCT3=$(echo $MASK|awk '{FS=".";print $3}')
OCT4=$(echo $MASK|awk '{FS=".";print $4}')
PHEX1=$(printf "%#x\n" $OCT1)
PHEX2=$(printf "%#x\n" $OCT2|sed 's/0x//')
PHEX3=$(printf "%#x\n" $OCT3|sed 's/0x//')
PHEX4=$(printf "%#x\n" $OCT4|sed 's/0x//')
if [ "$PHEX4" = "0" ]
then
PHEX4=00
fi
PHEXMASK=$(echo $PHEX1$PHEX2$PHEX3$PHEX4)
echo $PHEXMASK