-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomma2nl.py
executable file
·34 lines (28 loc) · 942 Bytes
/
comma2nl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
# comma2nl - Convert Comma(s) in Text Files to New Lines, Version 1.0
# Copyright 2020 ArdeshirV@protonmail.com, Licensed under GPLv3+
from sys import argv, exit
def main(args):
if len(args) < 2:
print("\033[0;31mError: \033[1;31mYou should"
" specify a file name to process!\033[0m")
return -1
file_input = open(args[1], "r")
contents = file_input.read()
file_input.close()
index = 0
contents_len = len(contents)
for i in range(0, contents_len):
c = contents[index]
if(c == ','):
index += 1
if contents_len <= index: break
print()
while(contents[index] == ' ' and contents_len - 1 > index):
index += 1
c = contents[index]
print(c, sep='', end='')
index += 1
if contents_len <= index: break
if __name__ == "__main__":
exit(main(argv))