Last digit minus ONE...
Hi All,
I am about configuring IP addresses for different workstations. in this process, after running few bash scripts to get the right subnet mask, i need to remove one digit from the last IP value, what i mean is: ex, if i get ip=192.168.0.254 i need 192.168.0.253 so whatever Ip address i get i need to minus only one digit from the last IP addresswhatever it is. What is the best way to do this.... Code:
$ip | cut -d"." -f4...... Thank you for your help. |
I'd say "Curtain B". You might be able to do something like this (I haven't tested):
Code:
$ip | awk -F"." ;'{printf "%d.%d.%d.%d", $1, $2, $3, $4 - 1}' |
Hi.
I agree, awk is better since it can do simple math. Code:
echo $ip | awk -F"." '{printf "%d.%d.%d.%d", $1, $2, $3, $4 - 1}' |
Thanks for the reply. it works as expected but yup how about the last 0 digit, i guess must test the IP address before running the code so if has 0 at the end ignores the IP address ...
|
Well it depends on whether you want go all bash or use outside commands:
Code:
ip='192.168.0.254' Of course this would require a lot more testing and work. |
Thanks Garil,
Once Again Short and Sweet...!! |
All times are GMT -5. The time now is 04:52 PM. |