search and store a value from linux command output in to variable python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: search and store a value from linux command output in to variable python (/thread-9404.html) |
search and store a value from linux command output in to variable python - prazy29 - Apr-06-2018 Hi I am a python bigginer, I have a scenario where I need to search and select a particular value from linux command "df -h". dumpe2fs 1.42.13.x5 (23-Mar-2017) Inode count: 786432000 In this above output I need to store the inode count number in to a variable to use it for further calculation. Can anyone explain how to use python regular expressions to do the above task? RE: search and store a value from linux command output in to variable python - wavic - Apr-06-2018 Get the output using subprocess. import subprocess output = subprocess.run(['df', '-h'], stdout=subprocess.PIPE).stdout output = output.decode('utf-8') for line in output.split('\n'): if line.startswith('Inode count:'): inode_cnt = int(line.split()[1])Something like that. Btw, I don't get the number of inodes with df -h .
|