import openpyxl

# Open the Excel file created by the previous script
workbook = openpyxl.load_workbook("rules.xlsx")

# Select the first worksheet
worksheet = workbook.active

# Loop through all rows in the worksheet, starting from the second row
for row in worksheet.iter_rows(min_row=2):
    # Remove spaces before commas in the third column and update the cell value
    logsource = row[2].value
    if logsource:
        logsource = logsource.replace(", ", ",")
        worksheet.cell(row=row[0].row, column=3, value=logsource)

# Save the modified worksheet to a new Excel file
workbook.save("rules.xlsx")
