LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-13-2019, 08:00 AM   #1
successlin
LQ Newbie
 
Registered: Dec 2011
Posts: 5

Rep: Reputation: Disabled
Replace last octet in IPV6 address


Hi ,
I want to replace last octet in ip6 address say "fd01:cab:1:29::23b" with "fd01:cab:1:29::1".
I tried using cut, and other operators like "%%*" but not able to successfully do it.
 
Old 06-13-2019, 09:27 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
The last octet or the last two octets? An octet is 8 bits.

Your example indicates you want two octets:
Code:
echo $IPADDRESS | sed ‘s/:[^:]*$/:1/‘
That replaces everything after the last colon. Testing is your responsibility.

If you only want to replace the last octet, it’s a bit more complicated, but should be doable with sed with little more effort.

Last edited by berndbausch; 06-13-2019 at 09:28 AM.
 
Old 06-13-2019, 05:19 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Personally I never use "*" unless absolutely unavoidable - it will match null expressions when you least expect it. Note also that sed supports the [:xdigit:] class.
 
1 members found this post helpful.
  


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
Get first day of last month and last day of last month in bash xowl Linux - Software 18 02-09-2017 09:49 AM
Cannot connect to ipv6 website with ipv6 address superweijiafeng Linux - Networking 3 07-08-2014 03:55 PM
How to use :%s to replace octet in IP range rhbegin Programming 5 04-06-2011 08:00 PM
convert simple ip address to 3 digit octet don_wombat_73 Linux - Newbie 12 07-07-2009 12:12 PM
How to set IPv6 address on IPv6 router tlemons Linux - Networking 3 09-17-2007 01:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:41 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