How to detect null values when delimiter is unknown?

0

I am currently working on the automation task of parsing Linux based outputs. We are currently not sure which field values will become null and when.

Goal: To get all the fields everytime no matter whichever field becomes null in my linux output. If any field is null then treat it as a blank field

Python code that I am using to split the fields: As there are no null fields in the output so the following code works as expected

fields = "Index    Id        Type              Ip      Flags AhmSt       CLT  AhmDB Nodename"
fields = fields.split()
output = "6215  5097     GOLD1      10.123.43.2        n/a [1,0,0,en]  dflt   u     testing-fake-sme-6-50.gold.isold.com"
values = output.split(' ')
values = [value for value in values if value]

values:
['6215', '5097', 'GOLD1', '10.123.43.2', 'n/a', '[1,0,0,en]', 'dflt', 'u', 'testing-fake-sme-6-50.gold.isold.com']

required_output = dict(zip(fields,values))
required_output:
{'Index': '6215', 'Nodename': 'testing-fake-sme-6-50.gold.isold.com', 'AhmDB': 'u', 'Ip': '10.123.43.2', 'Flags': 'n/a', 'CLT': 'dflt', 'AhmSt': '[1,0,0,en]', 'Type': 'GOLD1', 'Id': '5097'}

Now, for the following output my AhmSt field becomes null and the above code doesn't work.

output = "270  4142        HOLD     10.123.12.32 0x00000001                    h  hello-ca-4142-20.gold.isold.com

How can I detect in the second output that my AhmSt field is null and I have to update that with blank or None values?

python
asked on Stack Overflow Jun 21, 2019 by CHINTAN VADGAMA

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0