Linux - SoftwareThis 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.
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.
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.
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 ?.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.