Created
September 25, 2016 00:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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