Skip to content

Instantly share code, notes, and snippets.

@ollytheninja
Created February 22, 2022 22:39
Show Gist options
  • Select an option

  • Save ollytheninja/67f0e317d17bb13f5b34023744a115dc to your computer and use it in GitHub Desktop.

Select an option

Save ollytheninja/67f0e317d17bb13f5b34023744a115dc to your computer and use it in GitHub Desktop.
Find duplicate yor_trace tags
from pathlib import Path
globs = Path(".").glob("*/*.tf")
traces = []
duplicates = []
for glob in globs:
with glob.open() as f:
for line in f:
if "yor_trace" in line:
start = line.find('"')+1
end = line.find('"', start)
trace_tag = line[start:end]
if trace_tag in traces:
if trace_tag not in duplicates:
duplicates.append(trace_tag)
else:
traces.append(trace_tag)
print(f"Found {len(traces)} tags, {len(duplicates)} duplicates.")
if len(duplicates) > 0:
for dup in duplicates:
print(f" {dup}")
print("Remove all duplicates with the following:")
for dup in duplicates:
print("find . -type f -name \"*.tf\" -exec sed -i -e '/^.*"+dup+".*$/d' {} \;")
print('find . -type f -name "*.tf-e" -delete')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment