Skip to content

Instantly share code, notes, and snippets.

@avishaan
Last active June 12, 2022 02:01
Show Gist options
  • Save avishaan/e5d347c2e4defc9b6aa6d8812b9f94a6 to your computer and use it in GitHub Desktop.
Save avishaan/e5d347c2e4defc9b6aa6d8812b9f94a6 to your computer and use it in GitHub Desktop.
#!/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:])
@avishaan
Copy link
Author

python txt2csv.py -i pclaim_20220407_011310.txt -o pclaim_20220407_011310.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment