Skip to content
Advertisement

How to parse this particular console output and make csv?

I need to process console output which looks like this and make a csv from it:

JavaScript

I have managed to split lines but regex is not working for tabs and spaces. Can someone point me in the right direction?

The code I am using is this:

JavaScript

Advertisement

Answer

The regular expression can be handy here, make a mask, and then take each value from line read. you can refer the regex and will give you great visuals.

so for each line will put a regex reg_format=r"(d*?)(?:s+)(.*?)(?:s)(?:s*?)(w*.w*.w*.w*)(?:s*)(w*?:w*?:w*?:w*?:w*?:w*)(?:s*)(w*)(?:s*)(w*)(?:s*)(w*)"

pls note that when we write to csv using writer.writerow it expects a list. following would work for you, and you can tweak it as needed.

tweaked your code, and added the comments
Update: Added masking for records

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement