Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-07-2008, 01:13 PM   #1
LQ Newbie
Registered: May 2002
Posts: 20

Rep: Reputation: 0
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

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

Any help would greatly be appreciated.


Old 01-07-2008, 01:30 PM   #2
Senior Member
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
If it spits out "" and you need "" you could just append a piped "sed 's/1$/0/'
Old 01-07-2008, 02:58 PM   #3
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735
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")
Old 01-07-2008, 05:00 PM   #4
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Originally Posted by n1wil View Post
ifconfig eth1 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'

# 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.
Old 01-08-2008, 03:18 PM   #5
Registered: Dec 2006
Posts: 271

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
help to edit Edit my bootloader's config file from kernel prompt jagdishpandey Linux - Kernel 5 07-03-2007 07:59 AM
can sed edit individual characters/portions of a sentence? TGWDNGHN Linux - Software 10 10-18-2005 05:50 AM
Where can I edit my proxy IP address setting? Akhran Debian 2 10-15-2005 02:11 AM
Help with a script to edit text file (awk? sed?) rickh Linux - Newbie 8 04-21-2005 09:24 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM

All times are GMT -5. The time now is 10:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration