无法使用传入AWS SSM命令的awk筛选器打印第二个字段



我正在尝试从AWS SSM参数存储中获取详细信息。我存储了数据,SSM参数中的值存储如下:

公司名称\信用

请找到通过AWS CLI执行的SSM命令,输出如下:

aws ssm get-parameters --names "/Data/Details"
 - Output
{
    "Parameters": [
        {
            "Name": "/Data/Details",
            "Type": "String",
            "Value": "CompanyName\Credits",
            "Version": 1,
            "LastModifiedDate": "2019-08-13T18:16:40.836000+00:00",
            "ARN": "arn:aws:ssm:us-west-1:8484848448444:parameter/Data/Details"
        }
    ],
    "InvalidParameters": []
}  ```

In the above output, I am trying to print only **Credits** in **"Value": "CompanyName\Credits"**, so I have added more filters to my command as follows:
``` aws ssm get-parameters --names "/Data/Details" |grep -i "Value" |sed -e 's/[",]//g' |awk -F'\' '{print $2}' ```

The above command gives nothing in the output. But when I am trying to print the first field I am able  to see the output as  ** Value: CompanyName ** using the following command:
``` aws ssm get-parameters --names "/Data/Details" |grep -i "Value" |sed -e 's/[",]//g' |awk -F'\' '{print $1}' ```

Since this is Linux machine, the double slash in the field **Value : CompanyName\Credits ** occurred to escape the '' character for the actual value CompanyNameCredits. Can someone let me know how can I modify the command to print only the value **Credits** in my output.
Regards,
Karthik


我认为这应该有效:

param_info=$(aws ssm get-parameters 
    --names "/Data/Details" 
    --query 'Parameters[0].Value' 
    --output text)
echo ${param_info} | awk -F'\' {'print $3'}
# or without awk
echo ${param_info#*\\}  # for Credit
echo ${param_info%\\*}  # for CompanyName

这使用查询和输出参数来控制aws-cli的输出。还使用了bash参数展开。

最新更新