I would like to replace the second octet on an IP address using sed:
Example:
10.110.30.11
10.133.30.11
What is the easiest way to perform this task?
Thank you
An attempt in pure bash
, apart from wonderful awk
and sed
answers from above.
$ IFS="." read -r octet1 _ octet3 octet4 <<<"10.110.30.11"
$ octet2=133
$ printf "%s.%s.%s.%s\n" "$octet1" "$octet2" "$octet3" "$octet4"
10.133.30.11
With GNU sed:
sed 's/\.[0-9]\+\./.133./' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With