grep - JSONing 一个 Grepped 环境 (jq + grep + env)
问题描述
我只想从环境中获取 AWS_ 环境变量并将它们输出到 JSON 中。通常,做 env | grep AWS_ 向我显示正确的环境变量,而 jq -n env 会将整个环境显示为 JSON。
我试过了:
jq -n $(env | grep AWS_)
和
jq -n $(env $(grep AWS_))
两者都没有成功。
解决方案
There are many options, but since (as you point out) jq has an env
filter that produces the JSON for you, it would make sense to use it without having to invoke grep
and then parse the output to convert it to JSON. For example:
jq -n 'env | with_entries(select(.key | test("AWS_")))'
You might want to change the test to use "^AWS_".
推荐阅读
- html - 隐形汉堡菜单 HTML
- salesforce - salesforce SOQL with group by(分组依据之前的数学)
- vespa - 如何从另一个组件正确调用搜索
- typo3 - TYPO3:为详细视图正确生成 slug
- python - 输出未排序,无法对第二个值进行排序。是否有特殊方法对第二个值进行排序
- python - 如何用keras处理Conv1D的输入形状?
- amazon-web-services - 如何确定连接到 AWS IoT Core 的设备所在的国家/地区
- laravel - Laravel 关系类似于 belongsToThrough()
- c# - 如何从扩展方法注册 Mongo 客户端
- java - gradle run 任务的文档?