Skip to content

Instantly share code, notes, and snippets.

@TylerCode
Created April 15, 2025 17:04
Show Gist options
  • Save TylerCode/ea5c96c26c6a982cd25ed47599700320 to your computer and use it in GitHub Desktop.
Save TylerCode/ea5c96c26c6a982cd25ed47599700320 to your computer and use it in GitHub Desktop.
Takes a text file, removes lines that don't start with $, and makes a new CSV of only the $ entries.
def process_bonk_file(input_file="bonk.txt", output_file="bonk_fixed.csv"):
try:
with open(input_file, 'r') as f:
lines = f.readlines()
except FileNotFoundError:
print(f"Error: Could not find {input_file}")
return
except Exception as e:
print(f"Error reading file: {e}")
return
processed_lines = []
for line in lines:
line = line.rstrip()
if line.startswith('$'):
# Add comma to CSVify it and toss the $ otherwise excel will be a baby
processed_lines.append(line.replace('$','') + ',\n')
try:
with open(output_file, 'w') as f:
f.writelines(processed_lines)
print(f"Successfully processed {len(processed_lines)} lines and saved to {output_file}")
except Exception as e:
print(f"Error writing to output file: {e}")
return
if __name__ == "__main__":
process_bonk_file()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment