![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Printing value with no obvious field seperator | Donkey25 | Shell Programming and Scripting | 4 | 03-14-2008 06:57 AM |
| How to change field seperator | onthetopo | Shell Programming and Scripting | 2 | 05-11-2007 12:11 PM |
| regexp to print after a field seperator | ramky79 | Shell Programming and Scripting | 7 | 05-09-2007 06:31 PM |
| find columns with whitespace as field seperator? | tkbharani | UNIX for Advanced & Expert Users | 8 | 03-14-2007 01:13 AM |
| Using | as a seperator in join | firvin | UNIX for Dummies Questions & Answers | 5 | 03-28-2006 11:23 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Awk Field Seperator Help
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 |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|