Last active
June 12, 2022 02:01
-
-
Save avishaan/e5d347c2e4defc9b6aa6d8812b9f94a6 to your computer and use it in GitHub Desktop.
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
#!/bin/python | |
import sys, getopt, os | |
import csv | |
def main(argv): | |
inputfile = '' | |
outputfile = '' | |
# Get the current working | |
# directory (CWD) | |
cwd = os.getcwd() | |
try: | |
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="]) | |
except getopt.GetoptError: | |
print ('test.py -i <inputfile> -o <outputfile>') | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print ('test.py -i <inputfile> -o <outputfile>') | |
sys.exit() | |
elif opt in ("-i", "--ifile"): | |
inputfile = arg | |
elif opt in ("-o", "--ofile"): | |
outputfile = arg | |
if inputfile == outputfile: | |
print ('input file must be different from output file') | |
sys.exit() | |
print ('Input file is "', inputfile) | |
print ('Output file is "', outputfile) | |
with open(cwd + "/" + inputfile, "rt") as file_pipe: | |
with open(cwd + "/" + outputfile, 'wt') as file_comma: | |
csv.writer(file_comma, delimiter=';').writerows(csv.reader(file_pipe, delimiter='|')) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python txt2csv.py -i pclaim_20220407_011310.txt -o pclaim_20220407_011310.csv