0

I have a 12-digit MAC address such as 5C838F9FE398 which I need to replace with 5C83.8F9F.E398

Since I have to this for more than 200 MAC addresses I thought to use Notepad++ to save time. Is it possible to do it quickly with Notepad++?

1 Answer 1

5

Yes, this is possible.

Assuming the list of macaddresses look like this:

5C838F9FE398
5C838F9FE398
5C838F9FE398
5C838F9FE398

(where each is unique of course)

You can find/replace using regex.

Open the Find/Replace dialog by pressing CTRL+H.

In the Find What field, enter: ^(.{4})(.{4})(.{4})
In the Replace with field, enter: $1.$2.$3

At the bottom in the Search Mode group, select Regular Expression.

Now hit Replace All.


Explaining the Regex:

^          Only match if this happens at the beginning of a line
  (        Start of group 1 (to replace with $1)
    .{4}   Any character, 4 times
  )        End of group 1
  (        Same as above for group 2
    .{4}
  )
  (        Same as above for group 3
    .{4}
  )

Replacing is setup as:

 $1    These are the first 4 values found
 .     place a period next
 $2    These are the second 4 values found
 .     place a period next
 $3    These are the third 4 values found.

Anything after this string is completely ignored, and will remain present.

So 5C838F9FE398 test becomes 5C83.8F9F.E398 test

6
  • 1
    It might be better to specify a hex digit instead of any character by using ([0-9A-F]{4}) instead of each occurrence of (.{4}). This would be particularly necessary if there is other information in the file besides the MAC addresses, and even more so if the addresses are not at the start of the file: in the latter case you need something like \<([0-9A-F]{4})([0-9A-F]{4})([0-9A-F]{4})\> as the search string.
    – AFH
    Jun 9, 2016 at 12:16
  • Hi AFH, Brilliant many thanks. It solve my problem and saved me more than a half a day's work. Grateful.
    – Riz
    Jun 9, 2016 at 12:24
  • 1
    @Riz "Half a day"? You could do those changes by hand in 1/2 hour. Tedious but doable :)
    – DavidPostill
    Jun 9, 2016 at 12:28
  • 1
    Both work in NPP. I used the $ approach because I think it reads better in an answer on SuperUser.
    – LPChip
    Jun 13, 2016 at 17:45
  • 1
    @Riz Right thing to do now is to formally accept the answer, since the problem was solved, time was saved and you were grateful. Jun 27, 2016 at 7:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .