Created
February 3, 2016 15:05
-
-
Save cristovaov/403cc6ecefbb9518efd5 to your computer and use it in GitHub Desktop.
Search and stripping in a file. My first Python script y'all! I needed this to strip a SQL string,
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
import os | |
import sys | |
def main(): | |
print "\n" | |
fn = raw_input("Enter name of file: ") | |
print "Opening file: %s\n" % fn | |
if not os.path.exists(fn): | |
print("File does not exist!\n") | |
sys.exit | |
else: | |
str_search = raw_input("String to strip in file: ") | |
print "Searching for: %s\n" % str_search | |
with open(fn, "r") as infile, open("copy.txt", "w") as outfile: | |
data = infile.readlines() | |
for line in data: | |
rewrite = line.replace(str_search, "") | |
outfile.write(rewrite) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment