Python Forum

Full Version: Log process
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have a log that looks something like like this:
Field1=Value1, Field=Value2, Field3=Value3, Field4=Value4
Field1a=Value1a, Field2a=Value2a, Field3a=Value3a, Filed4a=Value4a


The goal is get this output

Value1 Value2 Value3 Value4
Value1a Value2a Value3a Value4a

I can do this in a a perl one-liner by getting everything into an array splitting by comma.
Then modifying the array and further splitting by equal sign.

What is the easiest and quickest way to accomplish this in python?

Thanks
(Aug-08-2017, 03:31 AM)besogon Wrote: [ -> ]I can do this in a a perl one-liner by getting everything into an array splitting by comma. Then modifying the array and further splitting by equal sign. What is the easiest and quickest way to accomplish this in python?

It is more or less the same - read the file line by line, split at commas, split at equal sign... you can use list comprehension or do it as a nested loop for example
Please, post your code if you need further assistance