gpt4 book ai didi

bash - 如何从一行中进行grep

转载 作者:行者123 更新时间:2023-12-05 01:45:20 25 4
gpt4 key购买 nike

我正在使用一个天气 API,它在一行中输出所有数据。如何使用 grep 获取“summary”和“apparentTemperature”的值?我对正则表达式的掌握基本上不存在,但我准备学习。

{"latitude":59.433335,"longitude":24.750486,"timezone":"Europe/Tallinn","offset":2,"currently":{"time":1485880052,"summary":"Clear","icon":"clear-night","precipIntensity":0,"precipProbability":0,"temperature":0.76,"apparentTemperature":-3.34,"dewPoint":-0.13,"humidity":0.94,"windSpeed":3.99,"windBearing":262,"visibility":9.99,"cloudCover":0.11,"pressure":1017.72,"ozone":282.98}}

谢谢!

最佳答案

How do I use grep to get the values for "summary" and "apparentTemperature"?

您使用 grep-o 标志,这使得它只输出匹配的部分。

由于您对正则表达式知之甚少,我建议您改为学习使用 JSON 解析器,它更适合此任务。

例如 jq , 以下命令将提取当前摘要:

<whatever is your JSON source> | jq '.currently.summary'

关于bash - 如何从一行中进行grep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41962786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com