无法使用传入 AWS SSM 命令的 awk 过滤器打印第二个字段
Unable to print the second field using awk filter passing in an AWS SSM Command
我正在尝试从 AWS SSM 参数存储中获取详细信息。我存储了数据,SSM 参数存储中的值是这样的:
CompanyName\credits
请找到通过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 }' ```
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 }' ```
Since this is Linux machine, the double slash in the field **Value : CompanyName\Credits ** occurred to escape the '\' character for the actual value CompanyName\Credits. 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 '}
# or without awk
echo ${param_info#*\\} # for Credit
echo ${param_info%\\*} # for CompanyName
这个用query and output parameters to control output from the aws cli. Also bash parameter expansions都用了
我正在尝试从 AWS SSM 参数存储中获取详细信息。我存储了数据,SSM 参数存储中的值是这样的:
CompanyName\credits
请找到通过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 }' ```
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 }' ```
Since this is Linux machine, the double slash in the field **Value : CompanyName\Credits ** occurred to escape the '\' character for the actual value CompanyName\Credits. 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 '}
# or without awk
echo ${param_info#*\\} # for Credit
echo ${param_info%\\*} # for CompanyName
这个用query and output parameters to control output from the aws cli. Also bash parameter expansions都用了