I'm new in python and regex and I have been trying to hide the IP Address logs in a txt file. I should avoid using for loops and if checks -if possible because txt file is huge (158MB).
(All the IP addresses starts with 172)
This is the code i tried:
import re
txt = "test"
x = re.sub(r"^172\.*", "XXX.\", txt)
print(x)
Sample txt file:
ABCDEFGHIJKLMNOPRST172.12.65.10RSTUVYZ
ASDG172.56.23.14FSDGHSFSDFDSFHSF
!'^%%&!'+!'+^%&!ÂSDBSDF172.23.23.23SADASFSA
ASGFGD 172.12.23.56 ASDSAFASFDASSADSA
Desired output:
ABCDEFGHIJKLMNOPRSTXXX.XXX.XXX.XXXRSTUVYZ
ASDGXXX.XX.XX.XXFSDGHSFSDFDSFHSF
!'^%%&!'+!'+^%&!ÂSDBSDFXXX.XXX.XXX.XXXSADASFSA
ASGFGD XXX.XXX.XXX.XXX ASDSAFASFDASSADSA