Grepping an ipaddress using ifconfig

Hi
I need to Grep for an ipaddress and need to substitute one octet with another octet
I have used the following code

gateway=`netstat -rn| grep default | tr -s " "|cut -d " " -f2 | head -1`

If the output is 9.3.94.1

I need to modify as 9.3.100.1

Please help

Can you please give us the output of netstat -rn| grep default ??

The output is

# echo $gateway
default 9.3.94.1 UG 6 37322 en0 - -

Hi Priya Amaresh,

Below script will get ipaddress and replace your desired octet at final echo command.

#!/bin/bash

gateway=`netstat -r | grep gateway | awk '{ print $2}'`
IFS="."
count=1
for iparray in ${gateway[@]}
do
    export ip$count="iparray"
    count=$((count+1))
done
echo "$ip1.$ip2.100.$ip4"

Using awk

netstat -rn | awk '/gateway/{ split($2,IP,"."); print IP[1],IP[2],100,IP[4] }' OFS="."