Advertisement
Python253

filter_lines

Mar 1st, 2024
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Filename: filter_lines.py
  3. # Author: Jeoi Reqi
  4. # This script reads lines from the input file, filters out lines starting with a custom filter & writes the remaining lines to the output file.
  5.  
  6. # Function to define the filter
  7. def filter_lines(input_file, output_file):
  8.     with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile:
  9.         for line in infile:
  10.             # Check if the line starts with "渝ICP备"
  11.             if not line.startswith("渝ICP备"):  # Edit this to match your filter goals
  12.                 outfile.write(line)
  13.  
  14. # Replace 'input.txt' with the name of your input file and 'output.txt' with the desired output file name
  15. input_file_name = 'input.txt'  # Replace 'input.txt' with the name of your input file
  16. output_file_name = 'output.txt'  # Replace 'output.txt' with the name of your output file
  17.  
  18. filter_lines(input_file_name, output_file_name)
  19.  
  20. print(f"Filtered lines starting with '渝ICP备' from {input_file_name} and saved the result in {output_file_name}.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement