Lets say I have a string that can be any possible/valid network address like so:
STR="192.168.1.0/24"
What I want to do is replace the last octet (in this case it's 0/24, however it can be anyting) with the number 2, however I don't know what the last octet could (do not will be print the new value, so change:
192.168.1.0/24
to:
192.168.1.2
Whatever the network address is, I want to replace the last octet with "2"
Note: it is not important to check if the string is a valid network address as all strings being tested are assumed to be valid network addresses.
myip = 192.168.0.1
into192.168.0.1/24
. This helped!$(awk -F"." '{print $1"."$2"."$3".1//24"}'<<<$myip)
– Twisty Sep 04 '20 at 21:45