24_deb_pkg_gov/12825_revision/txt_to_csv.py

23 lines
849 B
Python
Raw Normal View History

2025-01-30 23:19:27 +00:00
import re
def insert_comma_after_url(file_path):
# Regular expression pattern to match URLs
url_pattern = re.compile(r'(https?://[^\s]+)')
# Read the file with error handling for encoding issues
with open(file_path, 'r', encoding='utf-8', errors='replace') as file:
lines = file.readlines()
# Process each line to insert a comma after the URL
modified_lines = []
for line in lines:
modified_line = url_pattern.sub(r'\1,', line)
modified_lines.append(modified_line)
# Write the modified lines back to the file
with open(file_path, 'w', encoding='utf-8') as file:
file.writelines(modified_lines)
# Example usage
file_path = '/data/users/mgaughan/kkex/012825_cam_revision_main/12825_output_files/new_1750_3250-clone-error-output.txt'
insert_comma_after_url(file_path)