LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-12-2015, 02:15 PM   #1
summer68_01845@yahoo.com
LQ Newbie
 
Registered: May 2013
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 02-12-2015, 05:14 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,149

Rep: Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124
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 ?.
 
Old 02-13-2015, 07:28 AM   #3
summer68_01845@yahoo.com
LQ Newbie
 
Registered: May 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.
 
Old 02-13-2015, 10:49 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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.
Old 02-13-2015, 11:51 AM   #5
summer68_01845@yahoo.com
LQ Newbie
 
Registered: May 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
That worked! Thank you. I never would have figured that out.
 
  


Reply

Tags
sed


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
create file list: SED inline vs SED standalone, enormous speed difference Corsari Linux - Newbie 4 09-02-2013 03:01 AM
[SOLVED] Multipal line edited using sed, how to make sed specific coolpraz Programming 4 01-05-2013 01:14 PM
[Cygwin, sed] Using filenames as both files and search strings within sed lingh Linux - Newbie 5 10-20-2012 10:38 AM
[SOLVED] sed 's/Tb05.5K5.100/Tb229/' alone but doesn't work in sed file w/ other expressions Radha.jg Programming 6 03-03-2011 07:59 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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