-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMergeScript.py
More file actions
55 lines (46 loc) · 1.76 KB
/
MergeScript.py
File metadata and controls
55 lines (46 loc) · 1.76 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Multiple Files Version
# Windows ONLY. line 34 fails on Linux, will look into the cause.
import argparse
import os
import sys
parser = argparse.ArgumentParser(description='Merge numerical data in all the \
text files within a folder, sort, and then \
dump into one big text file')
parser.add_argument('-s',
'--source directory',
help='Folder containing source text files.',
required=True)
parser.add_argument('-d',
'--destination directory',
help='Destination directory of operation.',
required=True)
parser.add_argument('-st',
'--starting file',
help='Select any data text file within source folder.',
required=True)
args = vars(parser.parse_args())
path = args['source directory'] # Source path
output = args['destination directory'] + '/NewFile.txt'
outfile = open(output, 'w')
counter = 0
lines = file(args['starting file']).readlines()[1:]
for files in os.listdir(path):
if counter == 2:
lines.sort(key=lambda x: float(x.split()[0]))
for line in lines:
outfile.write(line)
outfile.close()
Proceed = raw_input('Check your output file. If you want to proceed, \
hit Y, otherwise hit N\n')
if Proceed == 'Y':
counter = 0
outfile = open(output, 'w')
lines += file(str(path) + '/' + str(files)).readlines()[1:]
elif Proceed == 'N':
sys.exit()
else:
counter += 1
lines += file(str(path) + '/' + str(files)).readlines()[1:]
for line in lines:
outfile.write(line)
outfile.close()