Advertisement
Python253

remove_duplicate_lines

Mar 1st, 2024 (edited)
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Filename: remove_duplicate_lines.py
  3. # Author: Jeoi Reqi
  4. # This script removes duplicate lines from a text file, preserving unique lines in sorted order & saves to specified file.
  5.  
  6. def remove_duplicates(input_file, output_file):
  7.     unique_lines = set()
  8.  
  9.     with open(input_file, 'r') as infile:
  10.         for line in infile:
  11.             unique_lines.add(line)
  12.  
  13.     with open(output_file, 'w') as outfile:
  14.         outfile.writelines(sorted(unique_lines))
  15.  
  16. if __name__ == "__main__":
  17.     input_file = "geolocations.txt"  # Replace with the actual input file name
  18.     output_file = "output_without_duplicates.txt"  # Replace with the desired output file name
  19.     remove_duplicates(input_file, output_file)  # Remove the duplicates
  20.  
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement