LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-07-2008, 12:13 PM   #1
n1wil
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 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
 
Old 01-07-2008, 12:30 PM   #2
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,178

Rep: Reputation: 49
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/'
 
Old 01-07-2008, 01:58 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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, 04:00 PM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,300
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by n1wil View Post
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.
 
Old 01-08-2008, 02:18 PM   #5
alkos333
Member
 
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?
 
  


Reply


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 06:59 AM
can sed edit individual characters/portions of a sentence? TGWDNGHN Linux - Software 10 10-18-2005 04:50 AM
Where can I edit my proxy IP address setting? Akhran Debian 2 10-15-2005 01:11 AM
Help with a script to edit text file (awk? sed?) rickh Linux - Newbie 8 04-21-2005 08:24 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 07:48 AM.

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