Skip to content

Instantly share code, notes, and snippets.

@jasonrwang
Created September 25, 2016 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonrwang/7e17b512068de8b449d5afc6294c2fdb to your computer and use it in GitHub Desktop.
Save jasonrwang/7e17b512068de8b449d5afc6294c2fdb to your computer and use it in GitHub Desktop.
Appends specified string to every line in a file - made for adding domain to a company email list
#!/usr/bin/python
# bulktext_append [ORIGINAL FILE] [SAVE FILE]
import sys
# Read in arguments for where to open and save the file
args = sys.argv
# Find what the user wants to add
append_text = input('Enter the string you would like to append to the text in quotations: ')
# Open original file with read permissions only
original_file = open(args[1], 'r')
original_file.close
original_text = original_file.read().splitlines()
# Clean the text from upper cases and spaces and append
new_text = [i.lower().replace(" ","") for i in original_text]
new_text = [i + append_text + '\n' for i in new_text]
# Write the modified text into a new file
new_file = open(args[2], 'w')
new_file.writelines(new_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment