Hi all,
I am quiet new in python, and I wish to have your help with re-formatting a text file. A portion of the input text.file is below:
Date 1936 10 1
CHANGE ‘10’
1.0
CHANGE ‘101’
0.4516
It mainly contains two keywords: DATE (year month day) and CHANGE (following be a variable like ‘10’ and a number like 1.0). What I want is to have it converted as the text.file below:
Date 1 Oct 1936
CHANGE ‘10’ good 1
CHANGE ‘101’ bad 0.4516
Changes includes: 1. Date reformat. Have the DATE (year month day) to DATE (day month year). And the month to be corresponding words rather than number, say 10 to be Oct. I guess we should have a check function which can assign number 1 to 12 with a right words “Jan, Feb, …Dec”.
2. Add ‘good’ or ‘bad’ after the CHANGE ‘variable’ (eg ‘10’). I have an array of variables (‘10’, ‘210’, ‘12w’, etc) to put ‘good’, while another array of variables (‘101’, ‘112w’, etc.) to put ‘bad’. So whenever the script meet ‘variable’ right after CHANGE, it can check whether this ‘variable’ is in good or bad groups. Then add a string after it.
It would be great if I could have python to do it since I have a long file. Any help or hint would be highly appreciated! Thank you very much!