Created
February 5, 2020 22:32
-
-
Save jpluscplusm/43eb911d9ed853a6a03e3a269cdc0937 to your computer and use it in GitHub Desktop.
AWK IPv4 to/from decimal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk | |
# 1-liner: awk '{for(i=0;i<4;i++){byte=$1%256;ip="." byte ip;$1-=byte;$1/=256}}END{sub(".","",ip);print ip}' | |
{ | |
for(i=0; i<4; i++) { | |
byte = $1 % 256 | |
ip = "." byte ip | |
$1 -= byte | |
$1 /= 256 | |
} | |
} | |
END{ | |
sub(".","",ip) | |
print ip | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk | |
# 1-liner: awk 'BEGIN{RS="."}{dec*=256;dec+=$1}END{print dec}' | |
BEGIN{ | |
RS="." | |
} | |
{ | |
dec*=256 | |
dec+=$1 | |
} | |
END{ | |
print dec | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment