Skip to content

Instantly share code, notes, and snippets.

@rasel-rz
Created August 8, 2020 12:05
Show Gist options
  • Save rasel-rz/818cda1046e8b7f498ee5e16cedd6a0c to your computer and use it in GitHub Desktop.
Save rasel-rz/818cda1046e8b7f498ee5e16cedd6a0c to your computer and use it in GitHub Desktop.
Usage: python txt2csv.py <TextFileName> <CSVFileName>
import csv
import sys
# print('x')
def main(inputFile, outputFile):
myFile = open(inputFile, "r")
with open(outputFile, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Date", "Name", "IP", "Description"])
for line in myFile:
data = line.split("\t")
writer.writerow(data)
print('success!')
if __name__ == "__main__":
if (sys.argv[1] is '') or (sys.argv[2] is ''):
print('Give file names properly')
else:
main(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment