Skip to content

Instantly share code, notes, and snippets.

@Karamu98
Last active April 26, 2019 17:14
Show Gist options
  • Save Karamu98/9d461ce91e991843a6ce9b509d40b6c2 to your computer and use it in GitHub Desktop.
Save Karamu98/9d461ce91e991843a6ce9b509d40b6c2 to your computer and use it in GitHub Desktop.
A simple tool to allow you to parse a file for data between two tags.
# This is a simple extractor tool, it will grab the data between two tags you define etc...
# ["This is my data right here"]: Start tag = "is ", End tag = " right". Output = "my data"
# To be noted, this will only work if the data you want is on seperate lines
fileLocation = input("File Location: ")
outputLocation = input("Output Location: ")
startTag = input("Start Tag: ")
endTag = input("End Tag: ")
def main():
# Read in the source file
file = open(fileLocation.replace("\"", ""), "r")
lines = file.readlines()
file.close()
# Set up the output file
outFile = open(outputLocation.replace("\"", ""), "w")
# Foreach line in each line of our source file
for line in lines:
splitByStart = line.split(startTag)
if len(splitByStart) > 1:
value = splitByStart[1].split(endTag)
outFile.write(value[0] + "\n")
# Close the write file
outFile.close()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment