I need to split the path defined in below code in following a manner that
k[0] = /dev/mapper/centos-root
k[1] = 52403200
k[2] = 14460252 an so on.
What have I tried?
I tried using the split function but it currently takes k[0] = /
also, I tried passing it into a list where the whole context comes as one value
command = ("df -P | egrep '([20][0-9]|100)%' | awk '{print}'|sed -e 's/ / : /g'")
command_execute = (stdin, stdout, stderr) = ssh.exec_command(command)
read_contents = stdout.read().decode("utf-8")
read_contents
'/dev/mapper/centos-root : : : : 52403200 : 14460252 : : 37942948 : : : : : : 28% : /n'
k=read_contents[0]
k
'/'
k=read_contents[1]
k
'd'
k.split(" ")
['d']
m =k.split(":")
m
['d']
s = [read_contents]
s
['/dev/mapper/centos-root : : : : 52403200 : 14460252 : : 37942948 : : : : : : 28% : /n']
s[0]
'/dev/mapper/centos-root : : : : 52403200 : 14460252 : : 37942948 : : : : : : 28% : /n'
s[1]
Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list index out of range
s[0]
'/dev/mapper/centos-root : : : : 52403200 : 14460252 : : 37942948 : : : : : : 28% : /n'
k[0] = /dev/mapper/centos-root
k[1] = 52403200
k[2] = 14460252 an so on.
3
Answers
You want to get rid of strings with whitespaces when you split on
:
Another option is to use
filter
function to select by the expected numbers length.Ouput: