Skip to content

Instantly share code, notes, and snippets.

@haifengkao
Created October 14, 2023 22:18
Show Gist options
  • Save haifengkao/498d437b5169c976f6fc6d3fed96288f to your computer and use it in GitHub Desktop.
Save haifengkao/498d437b5169c976f6fc6d3fed96288f to your computer and use it in GitHub Desktop.
remove duplicated lines in openmw.log
def remove_duplicates_ignore_timestamp(filename):
seen = set()
temp_filename = filename + '.temp'
with open(filename, 'r') as f, open(temp_filename, 'w') as temp_file:
for line in f:
# Strip the timestamp
stripped_line = line[12:]
if stripped_line not in seen:
seen.add(stripped_line)
temp_file.write(line) # Write the original line with timestamp
# Replace original file with the temporary file
import os
os.replace(temp_filename, filename)
if __name__ == "__main__":
filename = input("Enter the name of the file: ")
remove_duplicates_ignore_timestamp(filename)
print(f"Duplicates removed from {filename}!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment