如何在bash中解析命令输出

时间:2017-08-21 09:17:41

标签: bash

我在bash上执行命令,它给出了以下输出

bash-4.2$ soapcli.sh maxadmin "my_passw0rd" "http://localhost:8777/ws/pid/TpmLiteSoapService?wsdl" executeDeploymentRequest testCleanup "numeber=1234"
Result: 990823

如何存储结果,即990823在变量中。我使用以下命令将整个输出存储在变量中:

res=`soapcli.sh maxadmin "my_password" "http://localhost:8777/ws/pid/TpmLiteSoapService?wsdl" executeDeploymentRequest testCleanup "number=1234" 2>&1

echo $res
Result: 1234

1 个答案:

答案 0 :(得分:1)

通过管道awk| awk {print $2}命令添加到您的命令中:

bash-4.2$ soapcli.sh maxadmin "my_passw0rd" "http://localhost:8777/ws/pid/TpmLiteSoapService?wsdl" executeDeploymentRequest testCleanup "numeber=1234" | awk '{print $2}'