Skip to content

Commit b760f3a

Browse files
Anthony AgbyAnthony Agby
authored andcommitted
add delimiter script
1 parent e71081c commit b760f3a

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

MISC/delimiter.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import csv
2+
import os
3+
import re
4+
5+
def delimitFile(newDirectory, filename, delimiter, fileOutputName):
6+
# get the current working directory
7+
current_working_directory = os.getcwd()
8+
9+
# print output to the console
10+
print(current_working_directory)
11+
# Change the working directory
12+
os.chdir(newDirectory)
13+
14+
# Verify that the directory has changed
15+
print("New working directory:", os.getcwd())
16+
17+
try:
18+
with open(filename, 'r', encoding='latin-1') as infile, open(fileOutputName, 'w', newline='') as outfile:
19+
reader = csv.reader(infile)
20+
writer = csv.writer(outfile, delimiter=delimiter)
21+
22+
content = infile.read()
23+
trimmed_content = content[2:]
24+
25+
new_text = re.sub(r"\s+", delimiter, trimmed_content)
26+
split = new_text.split(delimiter)
27+
final_merge = "\n".join([delimiter.join(split[i:i+3]) for i in range(0,len(split),3)])
28+
29+
outfile.write(final_merge)
30+
except Exception as e:
31+
print("Error Occurred: ")
32+
print(e)
33+
34+
35+
#

0 commit comments

Comments
 (0)