[英]jq slurp and add key / value pairs
$DATA
is a long string containing some Email addresses. $DATA
是一个包含一些 Email 地址的长字符串。
echo "$DATA" | grep -Eo "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" | sort | uniq | jq --slurp --raw-input 'split("\n")[:-1]'
Output: Output:
[
"email1@mydomain.com",
"email2@mydomain.com",
"email3@mydomain.com",
"email4@mydomain.com"
]
Desired Output:所需的 Output:
[
{
"email": "email1@mydomain.com",
"free": "0",
"used": "0"
},
{
"email": "email2@mydomain.com",
"free": "0",
"used": "0"
},
{
"email": "email3@mydomain.com",
"free": "0",
"used": "0"
},
{
"email": "email4@mydomain.com",
"free": "0",
"used": "0"
}
]
I guess it should be something like += {"free": "0"}
我想应该是+= {"free": "0"}
You can replace your current jq
command by the following:您可以将当前的jq
命令替换为以下内容:
jq --slurp --raw-input 'split("\n")[:-1] | map({email: ., free: 0, used: 0})'
You can try it here .你可以在这里试试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.