Created
August 25, 2022 08:53
-
-
Save barryirwin/167e4269811f0fd002d885280aa6fc33 to your computer and use it in GitHub Desktop.
Converting from number of IP addresses to a /notation using awk
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
# easy case where /24 is the smallext allocation $1 is the number | |
$ echo 8192 | awk '{print 32-log($1)/log(2)}' | |
13 | |
$ echo 32 | awk '{print 32-log($1)/log(2)}' | |
5 | |
# this can be used to convert 1.2.4.0 8192 to 1.2.3.0/19 | |
$ echo 1.2.4.0 8192 | awk '{print $"/"32-log($2)/log(2)}' | |
1.2.3.0/19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment