Krish Krish -4 years ago 90
Bash Question

How to process CIDR block/Text processing?

I've to process CIDR block and add 2 to the last octet in single line to use it inside of a shell script.
For example, if my CIDR block is 10.0.0.0/8, then my output should be 10.0.0.2 only.

Answer Source

Assuming your line only contains the IP address and block, such as:

BLOCK=10.0.0.0/8

You can use awk:

cut -d/ -f1 <<< "$BLOCK" | awk -F . 'BEGIN {OFS="."} {print $1,$2,$3,$4+2}'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download