Python Forum
Parsing Text file having repeated value key pair using python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Parsing Text file having repeated value key pair using python (/thread-12003.html)



Parsing Text file having repeated value key pair using python - manussnair - Aug-04-2018

I have a text file that has the pattern as below..I would like to parse the values for each " An instance of Alert" and assign the values to the variables number,type,source etc..... What is the best option to accomplish this

Output:
An instance of Alert number=2 type=Server source=ARRAY.R800.56794 severity=4 component=DKC Environment description=Moderate error reported for DKC Environment. actionToTake=Contact your service representative. data=The component is not fully functional. timeOfAlert=2018/05/26 04:52:17 An instance of Alert number=1 type=Server source=ARRAY.R800.57457 severity=4 component=DKC Environment description=Moderate error reported for DKC Environment. actionToTake=Contact your service representative. data=The component is not fully functional. timeOfAlert=2018/05/26 04:07:42



RE: Parsing Text file having repeated value key pair using python - buran - Aug-04-2018

loop over file line by line
when the line is An instance of Alert - that's new alert
read following lines, split at = and you have key/value pair


RE: Parsing Text file having repeated value key pair using python - manussnair - Aug-04-2018

(Aug-04-2018, 07:36 PM)buran Wrote: loop over file line by line
when the line is An instance of Alert - that's new alert
read following lines, split at = and you have key/value pair
Do you have an example pls


RE: Parsing Text file having repeated value key pair using python - micseydel - Aug-04-2018

(Aug-04-2018, 07:45 PM)manussnair Wrote: Do you have an example pls
We get lot of people coming here and basically wanting us to do their homework. Because of this, we ask that all people show a code attempt at their problem (it doesn't matter if yours isn't homework). We have a whole tutorials section if you're having a hard time getting started.