We want to run the following shell command by python script ( we use python version 2.7 )
echo hadoop-hdfs-namenode - 2.6.4.0-91| grep hadoop-hdfs-namenode | awk '{print $NF}' | awk '{printf "%.1f\n", $NF}'
2.6
So I create the following python script to get the results - 2.6
import os
os.system("echo hadoop-hdfs-namenode - 2.6.4.0-91| grep hadoop-hdfs-namenode | awk '{print $NF}' | awk '{printf "%.1f\n", $NF}' ")
but when I run it we get
os.system("echo hadoop-hdfs-namenode - 2.6.4.0-91| grep hadoop-hdfs-namenode | awk '{print $NF}' | awk '{printf "%.1f\n", $NF}' ")
^
SyntaxError: invalid syntax
Is it possible to run this complicated shell via python ? , in order to get the expected results - 2.6
And how to fix my syntax?
subprocessmodule that is intended to replaceos.systemcalls.{printf "%.1f\n", $NF}to{printf '%.1f\n', $NF}