Sed 从json参数获取值不需要';t工作(jq:1编译错误)

Sed 从json参数获取值不需要';t工作(jq:1编译错误),sed,syntax,syntax-error,jq,Sed,Syntax,Syntax Error,Jq,我正在使用awscli并试图从查询的输出中获取IpAddress的值 我试图使用jq,但出现编译错误 情况就是这样: output="$(aws efs describe-mount-targets --file-system-id fs-089b5e31)" echo $output { "MountTargets": [ { "MountTargetId": "fsmt-bb29e666", "IpAddress": "172.20.33.255", "OwnerId": "66822555

我正在使用awscli并试图从查询的输出中获取IpAddress的值

我试图使用jq,但出现编译错误

情况就是这样:

output="$(aws efs describe-mount-targets --file-system-id fs-089b5e31)"
echo $output
{ "MountTargets": [ { "MountTargetId": "fsmt-bb29e666", "IpAddress": "172.20.33.255", "OwnerId": "668225551666", "SubnetId": "subnet-0b61377039d31e666", "NetworkInterfaceId": "eni-045f6ea1376662bdf", "FileSystemId": "fs-089b5e66", "LifeCycleState": "available" } ] }
这是我用来获取IpAddress的命令:

echo array | jq '.[]MountTarget[]s.IpAddress'
我得到的错误是:

parse error: Invalid numeric literal at line 2, column 0
ubuntu@ip-10-10-16-245:~/infra-devops/kops/vector$ echo array | jq '.[]MountTarget[]s.IpAddress'
jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
.[]MountTarget[]s.IpAddress
jq: 1 compile error
分析错误:第2行第0列的数值文字无效
ubuntu@ip-10-10-16-245:~/infra devops/kops/vector$echo数组| jq'.[]挂载目标[]s.IpAddress'
jq:error:syntax error,意外的标识符,在第1行处应为$end(Unix shell引用问题?):
[]装入目标[]s.IpAddress
jq:1编译错误

问题出在我的查询上,还是我最好改用sed?

您访问数组的语法错误。要获取IP地址,请使用以下命令:

aws efs describe-mount-targets --file-system-id fs-089b5e31 | 
  jq '.MountTargets[0].IpAddress'
MountTargets
是要从中获取第一个对象的数组

如果需要原始数据(不带双引号),请使用
jq
命令中的
-r
选项