import re import sys def redact_document(input_path, output_path): with open(input_path, 'r') as f: text = f.read() # 1. Names and Entities text = re.sub(r"SpecificName", "[ROLE/TITLE]", text) # 2. Vendors and Infrastructure text = re.sub(r"(?i)\bVendorName\b", "[VENDOR-TYPE]", text) text = re.sub(r"\bserver-hostname\b", "[SERVER-ROLE]", text) # 3. Domains and URLs text = re.sub(r'\bapp\.example\.com\b', 'app.[DOMAIN-REDACTED]', text) # 4. Standard Patterns (Emails, IPs) text = re.sub(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b', '[EMAIL-REDACTED]', text) text = re.sub(r'\b(?:\d{1,3}\.){3}\d{1,3}\b', '[IP-REDACTED]', text) with open(output_path, 'w') as f: f.write(text) if __name__ == '__main__': if len(sys.argv) != 3: print("Usage: python redact_template.py ") sys.exit(1) redact_document(sys.argv[1], sys.argv[2]) print(f"Redacted document saved to {sys.argv[2]}")