LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2010, 09:53 AM   #1
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Rep: Reputation: 16
Question Replacing the Last Digit


Hi

i am trying to replace the last digit in the ip address(25) with 47 using following:

Quote:
echo 192.168.0.25|sed -r s/([0-9]*\.[0-9]*\.[0-9]*)/47/g'
but not able so far, was wondering if you can help, so i can find my mistake.

Thanks
 
Old 06-23-2010, 09:57 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Seems similar to your previous thread.
 
Old 06-23-2010, 10:06 AM   #3
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Hi

Quote:
Seems similar to your previous thread.
With all respect, Never i ask anything twice!!

Have a Nice day!!
 
Old 06-23-2010, 10:36 AM   #4
Travis86
Member
 
Registered: Dec 2002
Location: The land of GMT -6
Distribution: OS X, PS2 Linux, Ubuntu, IRIX 6.5
Posts: 399

Rep: Reputation: 31
echo "192.168.0.25" | sed "s/\.[0-9]*$/\.47/"
 
Old 06-23-2010, 10:44 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Code:
echo "192.168.0.25" | awk -F. 'sub(/[0-9]+$/,"47")'
or sed:
Code:
echo "192.168.0.25" | sed -r 's/[0-9]+$/47/'

Last edited by grail; 06-23-2010 at 10:46 AM.
 
Old 06-23-2010, 11:16 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by grail View Post
Code:
echo "192.168.0.25" | awk -F. 'sub(/[0-9]+$/,"47")'
if there's already a field delimiter defined as ".", then just change field 4.
Code:
echo <ip> | awk -F"." '{$4="47"}1'  OFS="."
 
Old 06-23-2010, 11:37 AM   #7
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Thank you so much for all your help.
since i was working under DOS (windows) needed to change two things:

Quote:
echo 192.168.0.25| sed -r 's/[0-9]+$/47/'
take the dbl quote out & NO SPACE after echo. Spent almost my whole morning to find this one out!!!
it was pretty nasty to find out this way!!

Thank you ALL ...
 
  


Reply



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
[SOLVED] grep [[:digit:]] malfunctioning alphaniner Linux - General 9 10-21-2009 03:09 PM
Substitue single-digit, two-digit, and 3-digit numbers with text using sed dmason165 Programming 13 08-07-2009 10:38 AM
Two-digit integer value doesn't increment ahmedb72 Linux - Newbie 5 07-12-2009 05:37 AM
C - how to check whether it's a digit sycamorex Programming 10 02-28-2008 05:37 PM
54 digit numbers Scratchit General 3 06-23-2004 09:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:32 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration