-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMergeScript.py
40 lines (33 loc) · 1.49 KB
/
MergeScript.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
35
36
37
38
39
40
#Multiple Files Version
#Windows ONLY. line 20 fails on Linux, will look into the cause.
import os, sys
import argparse
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()