LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   SED: edit ip address (https://www.linuxquestions.org/questions/linux-software-2/sed-edit-ip-address-611786/)

n1wil 01-07-2008 12:13 PM

SED: edit ip address
 
Hi, I'm trying to figure out how to use sed to modify a returned ip address from the command:

ifconfig eth1 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'

When run, this returns 10.69.69.1

I need help to rewrite this to return the network address in the form of: 10.69.69.0

Any help would greatly be appreciated.

Thanks!

John

Poetics 01-07-2008 12:30 PM

If it spits out "10.69.69.1" and you need "10.69.69.0" you could just append a piped "sed 's/1$/0/'

pixellany 01-07-2008 01:58 PM

First, why is it returning the wrong address?

Second, do you need to change any digit in the last position to zero? (or just "1" to "0")

David1357 01-07-2008 04:00 PM

Quote:

Originally Posted by n1wil (Post 3014581)
ifconfig eth1 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'

Try

Code:

# ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/\([a-z]\+[:]\)// | sed -e 's/\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)/\1\.\2\.\3\.0/'
The first sed script will remove the "inet addr:" and the second one will replace the last octet with 0.

alkos333 01-08-2008 02:18 PM

Could you please be more specific as to what output you are getting and what you would like to modify it to?


All times are GMT -5. The time now is 12:22 PM.