Python Forum
Parsing Text file having repeated value key pair using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parsing Text file having repeated value key pair using python
#1
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
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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
Reply
#4
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Text parsing Arik 5 400 Mar-11-2024, 03:30 PM
Last Post: Gribouillis
  Replace a text/word in docx file using Python Devan 4 3,368 Oct-17-2023, 06:03 PM
Last Post: Devan
  save values permanently in python (perhaps not in a text file)? flash77 8 1,231 Jul-07-2023, 05:44 PM
Last Post: flash77
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,869 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,124 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,672 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Parsing xml file deletes whitespaces. How to avoid it? Paqqno 0 1,036 Apr-01-2022, 10:20 PM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,977 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Getting the maximum value:key pair from a dictionary sean1 2 1,443 Jan-17-2022, 01:04 PM
Last Post: DeaD_EyE
  Parsing a syslog file ebolisa 11 4,136 Oct-10-2021, 05:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020