Hi All,
I would like to run a shell command and depending on the output - if following a certain pattern - save the results into individual sets.
Basically it is like this:
Run shell command (subprocess.Popen(cmd))
Save output to variable (out, err = p.communicate())
Process saved data into separate variables/dictionaries/lists (not sure which is best?)
Note: Expected output can be like this (there can be several batches but with different data)
Code:
process results from shell...
Name = Andy
Gender = Male
UniqueID = [11:22:33:44]
Age = 28
Name = Debbie
Gender = Female
UniqueID = [22:33:44:55]
Age = 29
Driver = Yes
Name = Steven
Gender = Male
UniqueID = [33:44:55:66]
Age = 27
Done
I would like to be able to understand:
Number of data sets (using above example should be =3)
Each dataset stored and callable (So to print set.3 I expect to see:
Code:
Name = Steven
Gender = Male
UniqueID = [33:44:55:66]
Age = 27
Or I can use parts of each set (So to print set.3.UniqueID I expect to see:
I do not want to store empty spaces and/or preceeding/following or 'unwanted' data such as:
Code:
process results from shell...
Done
Driver = (This unwanted entry appears in second data set)
-------------------------------------------
Where am I now:
I can save the output to variable but do not know how to sort it. I was looking at regex, grep etc but don't know how to make this robust. ie. it could be that 10 datasets are returned and should be saved accordingly.