I'm trying to write a program to sort and tag lines in a file. For example, suppose I have a .txt file of a health clinic with a variety of information about a patient. I want to tag the information. Suppose the data is given in the following order:
Patient ID
Age
Gender
Height
Weight
HBA1C level
Cholesterol
Smoker status
Systolic BP
Diastolic BP
And suppose the file contains the following information (all of which is made up):
A31415
54
M
180
90
6.7
100
No
130
65
A32545
62
F
160
80
7.2
120
Yes
180
92
My problem is trying to write a loop for each patient, with
A31415
54
M
180
90
6.7
100
No
130
65
being one patient and
A32545
62
F
160
80
7.2
120
Yes
180
92
being the second. I'm struggling to get the code to produce the following result:
<patient>
<patientID> A31415 </patientID>
<clinic> UIHC </clinic>
<age> 54 </age>
<gender> M </gender>
<height> 180 </height>
<weight> 90 </weight>
<hba1c> 6.7 </hba1c>
<cholesterol> 100 </cholesterol>
<smoker> No <smoker>
<systolic> 130 </systolic>
<diastolic> 65 </diastolic>
</patient>
<patient>
<patientID> A32545 </patientID>
<clinic> UIHC </clinic>
<age> 62 </age>
<gender> F </gender>
<height> 160 </height>
<weight> 80 </weight>
<hba1c> 7.2 </hba1c>
<cholesterol> 120 </cholesterol>
<smoker> Yes </smoker>
<systolic> 180 </systolic>
<diastolic> 92 </diastolic>
</patient>
Any help would be greatly appreciated.