Hi all, the value in the following file is just an example. It could be a different value/network addresses.
Here is my example of initial output in a file name net.txt
Initial Output, net.txt
Quote:
10.0.0.0/8
172.16.1.0/16
192.168.1.0/24
The goal is to produce the following format which is to convert from CIDR to Netmask formatting.
Quote:
10.0.0.0 255.0.0.0
172.16.1.0 255.255.0.0
192.168.1.0 255.255.255.0
My current draft script which is not perfect is to use “sed” to replace “/24” with “255.255.255.0” format. This is part of network subnetting conversion.
This is to print the initial net.txt value and save the final output to net-mask.txt
Quote:
#!/bin/bash
awk '{
print "$1;
}' net.txt > net-mask.txt
Quote:
sed 's/\/8/ 255.0.0.0/'
sed 's/\/16/ 255.255.0.0/'
sed 's/\/24/ 255.255.255.0/'
or
Quote:
sed 's#/8# 255.0.0.0#'
sed 's#/16# 255.255.0.0#'
sed 's#/24# 255.255.255.0#'
Or course the sed script for CIDR to netmask table above is not complete. The full list of the conversion can be found here.
Netmask / CIDR Translation Table
Please let me know where is the best place to put “sed” into my shell script file.
If there is better way to do this, please let me know. Thanks in advance.