Created
August 8, 2020 12:05
-
-
Save rasel-rz/818cda1046e8b7f498ee5e16cedd6a0c to your computer and use it in GitHub Desktop.
Usage: python txt2csv.py <TextFileName> <CSVFileName>
This file contains hidden or 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 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