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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-12-2015, 02:15 PM
|
#1
|
LQ Newbie
Registered: May 2013
Posts: 5
Rep: 
|
Help using sed
I have an output file where the string "mac address =" will always be on each line, but the location of the string may be at a different byte. For example:
SERVER-A <00> - IP ADDRESS = 192.168.10.10 <ACTIVE> mac address = 00-1A-A0-A0-D9-1D
mac address = EC-9A-74-64-E5-5D PRINTER-A.DOMAIN.COM - P <ACTIVE>
I want to strip the "-" out of the MAC Address only as there can be other "-" in each line. So I'd like the output to look like this.
SERVER-A <00> - IP ADDRESS = 192.168.10.10 <ACTIVE> mac address = 001AA0A0D91D
mac address = EC9A7464E55D PRINTER-A.DOMAIN.COM - P <ACTIVE>
I'm guessing that sed should be used, but have no idea how to achive the desired result.
Thanks in advance.
|
|
|
02-12-2015, 05:14 PM
|
#2
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,415
|
Define the data in the input, and what you want as output:
two alphanumerics, minus sign,two alphanumerics, minus sign, ...
two alphanumerics,two alphanumerics, ...
Sed supports character classes (with repeat counts) and back references to handle the above. What is your sed (regex really) comfort level ?.
|
|
|
02-13-2015, 07:28 AM
|
#3
|
LQ Newbie
Registered: May 2013
Posts: 5
Original Poster
Rep: 
|
Correct. I want the MAC Address minus the hyphen symbol but I also want to retain all the other information in each line. My comfort/knowledge of sed is a 3 on a scale of 10. I could do a simple sed 's/-//g' but that would also remove hyphens that are not a part of the MAC Address. Thank you.
|
|
|
02-13-2015, 10:49 AM
|
#4
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,827
|
There's probably a less messy solution, but
Code:
sed -r 's/([[:xdigit:]]{2})-([[:xdigit:]]{2})-([[:xdigit:]]{2})-([[:xdigit:]]{2})-([[:xdigit:]]{2})-([[:xdigit:]]{2})/\1\2\3\4\5\6/'
yields the result you showed. I didn't actually match the "mac address =" string, just anything that had the pattern of 6 pairs of hex digits separated by minus signs.
|
|
1 members found this post helpful.
|
02-13-2015, 11:51 AM
|
#5
|
LQ Newbie
Registered: May 2013
Posts: 5
Original Poster
Rep: 
|
That worked! Thank you. I never would have figured that out.
|
|
|
All times are GMT -5. The time now is 09:08 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|