Formatting a MAC address

I’m often given huge lists of MAC addresses and they tend to arrive in a variety of different formats. Such as the following:

AABBCCDDEEFF
AA-BB-CC-DD-EE-FF
AAB.BCC.DDE.EFF
AABB.CCDD.EEFF
AA:BB:CC:DD:EE:FF

Typically I need them formatted as the last example above, with colons between every 2 characters.

The formula below works great in Excel, where A2 is the cell you’re targeting:

=LEFT(A2,2)&”:”&MID(A2,3,2)&”:”&MID(A2,5,2)&”:”&MID(A2,7,2)&”:”&MID(A2,9,2)&”:”&RIGHT(A2,2)

Splitting a CSV file

I was a little reluctant to push out a change that would affect nearly 600 Access Points, so I wanted to do it in batches of 100. As the method of input was CSV, I needed to break this up.

The Split command from the GNU coreutils was the perfect solution for my needs.

split -l 100 list.csv –additional-suffix=.csv output/test -d

The output of that command produces the following files, each with 100 lines of data and places them inside the directory named output.

test01.csv
test02.csv
test03.csv
test04.csv
test05.csv
test06.csv

Without the –additional-suffice and -d options the files would not have the extension I was looking for, and it would have been ordered alphabetically instead of numerically.