I have over 500 MAC addresses and I'm trying to find a simple way to insert colons between every 2 characters.
+4
A:
You could get notepad++ and do a search and replace with regex like search for (..) and replace with \1:
Matt
2009-06-29 23:27:05
Why would '\1-' insert a colon?
Jonathan Leffler
2009-06-30 00:20:03
Woops sorry should be \1:
Matt
2009-06-30 00:23:11
A:
It maybe overkill, but I would use Excel. Paste your MAC addresses into column A and this formula into column B:
=LEFT(A1,2)&":"&MID(A1,3,2)&":"&MID(A1,5,2)&":"&MID(A1,7,2)&":"&MID(A1,9,2)&":"&RIGHT(A1,2)
Then, you can copy
column B, and either paste special...values
into column C or just paste into Notepad.
Kevin Hakanson
2009-06-29 23:39:01
+3
A:
You could use a sed command such as this:
sed 's/\(\w\w\)\(\w\w\)\(\w\w\)\(\w\w\)\(\w\w\)\(\w\w\)/\1:\2:\3:\4:\5:\6/g' filename
This will just pull out 12 characters in groups of two, and spit them back out with colons in the middle. You could also try a simpler pattern like s/(\w\w)/\1:/g, though this will leave you with an extra colon at the end of every address.
Nick Lewis
2009-06-29 23:42:11
Beat me to it! In re to your last sentance, you could then use another sed command to strip the trailing colon, and it might still be shorter.
TokenMacGuy
2009-06-29 23:43:31
Not all versions of 'sed' support '\w' to mean a word-character. Greater precision in the match ('[0-9a-fA-F]') would make the iterative solution preferable.
Jonathan Leffler
2009-06-30 00:21:37
I'd personally probably do it in Perl, but I have to upvote the decently simple Regex way of doing it.perl -e "while (<>) {$_ =~ s/(\w{2})/$1:/g; s/:$/$/;}".. I think that one would do it.
Sector Corrupt
2009-06-30 00:58:35