Guest User

Untitled

a guest
Mar 3rd, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. def extract_free_lines(input_file, output_file):
  2. free_lines = []
  3.  
  4. with open(input_file, 'r', encoding='utf-8') as f_in:
  5. for line in f_in:
  6. # Remove trailing whitespace and newlines
  7. line = line.rstrip()
  8. # Check if line ends with "(free)"
  9. if line.endswith("(free)"):
  10. free_lines.append(line)
  11.  
  12. with open(output_file, 'w', encoding='utf-8') as f_out:
  13. for line in free_lines:
  14. f_out.write(line + '\n')
  15.  
  16. # Replace these with your full paths
  17. input_path = 'C:\\path\\to\\your\\input.txt' # Windows example
  18. output_path = 'C:\\path\\to\\your\\output.txt'
  19.  
  20. # For Linux/Mac, use format like:
  21. # input_path = '/path/to/your/input.txt'
  22. # output_path = '/path/to/your/output.txt'
  23.  
  24. # Run the function with full paths
  25. extract_free_lines(input_path, output_path)
Advertisement
Add Comment
Please, Sign In to add comment