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, then my output should be only.

Answer Source

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


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