Search and replace: inserting colons in multiple lists?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
daniel.337
Posts: 13
Joined: Wed Aug 19, 2009 12:53 pm

Search and replace: inserting colons in multiple lists?

Post by daniel.337 »

Hi there,

I have a huge amount of lists with documentated MAC addresses.

Unfortunately many of these entries are written down in the following format:

Code: Select all

38F3A4C4FAE2
To get a better readable and viewable style of the MAC addresses I would like to change all of this entries automatically to this format, inserting colons between each hexadecimal octet:

Code: Select all

38:F3:A4:C4:FA:E2
Is it possible to this automatic insertion via the function "Search and Replace" in TextPad? This would be great.

Regards,
Daniel
Last edited by AmigoJack on Tue Apr 11, 2023 11:32 am, edited 1 time in total.
Reason: better title; adding description of what to want so searching for it finds this text, too
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Re: Search and replace: inserting colons in multiple lists?

Post by ben_josephs »

Search | Replace... (<F8>):
Find what: ([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})
Replace with: $1:$2:$3:$4:$5:$6

[X] Regular expression

Replace All
You can save that as a macro.
User avatar
daniel.337
Posts: 13
Joined: Wed Aug 19, 2009 12:53 pm

Re: Search and replace: inserting colons in multiple lists?

Post by daniel.337 »

Wow, great, this is what I was searching for.

Thank you very much! :D

Daniel
User avatar
AmigoJack
Posts: 532
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Re: Search and replace: inserting colons in multiple lists?

Post by AmigoJack »

Yes:
  1. Open all "lists" (I suppose files) in TextPad. Of course: start with 2-5 for testing all this first.
  2. Press F8 or select Search > Replace... to get that dialog.
  3. Tick Conditions > Regular expressions since you want to match a pattern instead of exact texts.
  4. Tick Conditions > Match case in case the letters are really all uppercase - this reduces matching false positives.
  5. Tick Scope > All documents to perform this on all opened files.
  6. Find what:

    Code: Select all

    ([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})
  7. Replace with:

    Code: Select all

    \1:\2:\3:\4:\5:\6
  8. Click Replace All.
  9. Close dialog.
  10. Press Ctrl+Shift+S or select File > Save all to store all modifications to the open files.
However, if your list format is more distinctive (f.e. the MAC addresses always appear on their own line, or always from position 12 to 24, or always come with this or that prefix), then the regex can be more specific, really only matching what you want. By now it would also match the word DEADCAFEBABE or numbers like 017588439425.
Post Reply