trim last octate of ip address using bash script

Hi,
i need to replace the last octate in ipaddress with 0 using bash shell for one of my applicatiom.
googling i found the below link where they do the same thing but use long2 ip which i dont see in linux.

trim ip address octet - Stack Overflow

Plz can soemone guide how do i do this using bash shell script?

Thanks in advance..

Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future
All firsts posts from new members are moderated (especially if a link is included!) so please be patient, a moderator has to approve your post before it appears in the forum...
Thank You.

The UNIX and Linux Forums.

here is a simple shell test.sh to do what you want

cat test.sh
ip=$1
baseip=`echo $ip | cut -d"." -f1-3`
echo $baseip".0"
./test.sh 192.168.133.14
192.168.133.0

wow!! thanks a lot :slight_smile:

Or ...

echo 192.168.133.14 | sed 's/\.[0-9]*$/.0/'

ok. thanks a lot.. :slight_smile: