The main txt (data.txt) contains for example:
Lib ID 4444
QT ID 4444
SOQ ID 80
MAC ID 21563
LED ID 4444
TRD ID 80
CAD ID 31256
OIL ID 21563
MNO ID 3315
TOP ID 638
And the list goes on. The numbers are from minimum 2 to 5 digits. What I am trying to do is to match the same numbers and save them in separated txt files. The files can be saved by the number's name or it can be anything random. For example, it will save the below IDs in a separate txt file (4444.txt or random.txt):
LED ID 4444
QT ID 4444
Lib ID 4444
It will save 80 in different txt:
TRD ID 80
SOQ ID 80
Save another match in different txt:
OIL ID 21563
MAC ID 21563
And the lines with unique numbers will be saved in a different txt for example (unique.txt):
MNO ID 3315
TOP ID 638
CAD ID 31256
I have tried using this regex:
(\d)(?!\1+$)\d*
it matches the similar numbers but I am stuck on separating them. Any help will be greatly appreciated.