I have parsed a file and I need some help in splitting a data in it. Below is my data:
Block of data:
blank space
20/06/25 12:19:33 ERROR datasources
20/06/25 21:12:23 ERROR sadasdfsd
blank space
blank space
20/06/25 12:19:33 WARN asda
20/06/25 21:12:23 ERROR asdasdfsd
20/06/25 12:20:33 WARN asda
blank space
I have mentioned 'blank space' for better understanding.In my data there will be empty space there
The code I tried:
def parse_log_contents(text,full_text_lines,filter_content_types=None):
#print(text) #Above block of data
messages = re.compile('^(?=\d+/)',flags=re.MULTILINE).split(text)
print(messages)
The output I got:
['']
['20/06/25 12:19:33 ERROR datasources\n20/06/25 21:12:23 ERROR sadasdfsd']
['']
['']
['20/06/25 12:19:33 WARN asda\n20/06/25 21:12:23 ERROR asdasdfsd\n20/06/25 12:20:33 WARN asda']
['']
Expected Output:
['']
['', '20/06/25 12:19:33 ERROR datasources\n', '20/06/25 21:12:23 ERROR sadasdfsd']
['']
['']
['', '20/06/25 12:19:33 WARN asda\n','20/06/25 21:12:23 ERROR asdasdfsd\n','20/06/25 12:20:33 WARN asda']
['']
I use python 2.7 in Linux Environment
In my output you can see I wasn't able to split the errors by delimiter comma(,).
Also I need a empty '' in front of those messages which I will need later for other processing .
Please help me to sort this issue.Thanks a lot!
r. Then you could try splitting withr'(^|\n)(?=\d+/)'instead.