Skip to content

Instantly share code, notes, and snippets.

@robertdevore
Last active December 10, 2022 04:56
Show Gist options
  • Save robertdevore/82d6613334d27c1fd923a1ccdc9e5328 to your computer and use it in GitHub Desktop.
Save robertdevore/82d6613334d27c1fd923a1ccdc9e5328 to your computer and use it in GitHub Desktop.

Remove blank lines from txt file

This script reads in the input file line by line and writes the encoded lines to the output file. It skips any empty lines in the input file.

You can use this script by replacing input.txt with the name of your input file and output.txt with the name of the output file you want to create.

Useful for when you have a password or vuln list that has blank lines you need to clean up before running them through your scanners.

# Open the input file
with open('input.txt', 'r') as f_input:
# Open the output file
with open('output.txt', 'w') as f_output:
# Iterate over the lines in the input file
for line in f_input:
# Remove any whitespace from the beginning and end of the line
line = line.strip()
# Skip empty lines
if not line:
continue
# Encode the line and write it to the output file
f_output.write(line.encode('utf-8'))
f_output.write('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment