为JQ中的值分配键
JQ有没有办法从这个Stdout进行:
Thu Jun 9 10:09:14 AM EDT 2022IP86.75.30.9
对此?:
{
"date": "Thu Jun 9 10:09:14 AM EDT 2022",
"ip": "86.75.30.9"
}
我能够以此
为目标:
echo $(date)IP$(myip.sh) | jq -R 'split("IP")'
输出此信息:
[
"Thu Jun 9 10:09:14 AM EDT 2022",
"86.75.30.9"
]
谢谢!
Is there a way in jq to go from this stdout:
Thu Jun 9 10:09:14 AM EDT 2022IP86.75.30.9
to this?:
{
"date": "Thu Jun 9 10:09:14 AM EDT 2022",
"ip": "86.75.30.9"
}
I was able to get part of the way there
with this:
echo $(date)IP$(myip.sh) | jq -R 'split("IP")'
that outputs this:
[
"Thu Jun 9 10:09:14 AM EDT 2022",
"86.75.30.9"
]
thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
date
和ip
键创建一个对象,其中您将相应地分配第一个和第二个索引:将产生
在线示例
You can create an object with the
date
andip
key in which you'll assign the first and second index accordingly:Will produce
Online example
使用
捕获
可能会派上用场:demo
Using
capture
might come in handy:Demo
混合 jq with shell参数扩展:
Mixing jq with Shell Parameter Expansion: