Quote:
| Originally Posted by rrashkin You haven't really given us enough information to determine how to choose which input data goes into the output. NTL, here are some ideas.
Initialize a list for the output: outlist=[]
Put the names of the input files in a list: infiles=["/blah/blah/blah/file1.txt", "/blah,blah,blah/file2.txt",...]
Loop through the input files and split each line:
Code:
for f in infiles:
fid=open(f)
for rec in fid:
data=rec.split()
Now key1=data[0], etc, and the data is data[3:] |
Sorry rrashkin about my vague question. To clarify the question, we will have three sections in each of the input files and all the data from the input files from each section should be written to a separate text file. For example we have 2 input files:
Input File1:
Section1
PKey1 PKey2 PKey3 Data1 Data2 Data3
Key1 Key2 Key3 80 100 0.90
Key1 Key2 Key4 85 101 0.89
Key2 Key3 Key4 100 125 0.89
Input File2:
Section1
PKey1 PKey2 PKey3 Data1 Data2 Data3
Key1 Key2 Key3 85 110 0.90
Key1 Key2 Key4 80 151 0.89
Key2 Key3 Key4 102 135 0.99
Key3 Key4 Key5 110 167 0.87
Output file for Section:
-------------------XXXXX-File1-XXXX---XXXXX-File2-XXXXX
PKey1 PKey2 PKey3 Data1 Data2 Data3 Data1 Data2 Data3
Key1 Key2 Key3 80 100 0.90 85 110 0.90
Key1 Key2 Key4 85 101 0.89 80 151 0.89
Key2 Key3 Key4 100 125 0.89 102 135 0.99
Key3 Key4 Key5 N/A N/A N/A 110 167 0.87
If a data exists in one file but not in the other we need to put "N/A" in the file where it does not exist. The same output follows for the other 2 sections.
Hope I clarified the question.
Thanks
rk