好友
阅读权限10
听众
最后登录1970-1-1
|
kover
发表于 2022-10-13 21:38
本帖最后由 kover 于 2022-10-14 11:42 编辑
curl下来的json数据是这样的
{"nums":5,"cityid":"101220103","city":"西宁","update_time":"2022-10-13 17:31:43","data":[{"date":"2022-10-13","wea":"晴转多云","wea_img":"yun","tem_day":"29","tem_night":"17","win":"东北风","win_speed":"<3级"},{"date":"2022-10-14","wea":"晴","wea_img":"qing","tem_day":"29","tem_night":"19","win":"东北风","win_speed":"<3级"},{"date":"2022-10-15","wea":"晴","wea_img":"qing","tem_day":"30","tem_night":"20","win":"东北风","win_speed":"<3级"},{"date":"2022-10-16","wea":"晴转多云","wea_img":"yun","tem_day":"31","tem_night":"20","win":"东北风","win_speed":"<3级"},{"date":"2022-10-17","wea":"晴转多云","wea_img":"yun","tem_day":"31","tem_night":"17","win":"东北风","win_speed":"<3级"},{"date":"2022-10-18","wea":"晴转多云","wea_img":"yun","tem_day":"28","tem_night":"15","win":"东北风","win_speed":"<3级"},{"date":"2022-10-19","wea":"晴","wea_img":"qing","tem_day":"28","tem_night":"15","win":"东北风","win_speed":"<3级"}]}
格式化后大概这样的
{"nums":3,
"cityid":"101220103",
"city":"西宁",
"update_time":"2022-10-13 16:05:29",
"data":[
{
"date":"2022-10-13",
"wea":"晴转多云",
"wea_img":"yun",
"tem_day":"29",
"tem_night":"17",
"win":"东北风",
"win_speed":"<3级"
},
{
"date":"2022-10-14",
"wea":"晴",
"wea_img":"qing",
"tem_day":"29",
"tem_night":"19",
"win":"东北风",
"win_speed":"<3级"
},
{
"date":"2022-10-15",
"wea":"晴",
"wea_img":"qing",
"tem_day":"30",
"tem_night":"20",
"win":"东北风",
"win_speed":"<3级"
},
{
"date":"2022-10-16",
"wea":"晴转多云",
"wea_img":"yun",
"tem_day":"31",
"tem_night":"20",
"win":"东北风",
"win_speed":"<3级"
},
{
"date":"2022-10-17",
"wea":"晴转多云",
"wea_img":"yun",
"tem_day":"31",
"tem_night":"17",
"win":"东北风",
"win_speed":"<3级"
},
{
"date":"2022-10-18",
"wea":"晴转多云",
"wea_img":"yun",
"tem_day":"28",
"tem_night":"15",
"win":"东北风",
"win_speed":"<3级"
},
{
"date":"2022-10-19",
"wea":"晴",
"wea_img":"qing",
"tem_day":"28",
"tem_night":"15",
"win":"东北风",
"win_speed":"<3级"
}]}
我想要这样的结果
近7天西宁天气
2022-10-13 晴转多云 17-29°C 东北风3级
2022-10-14 晴 19-29°C 东北风3级
....
2022-10-19 晴 15-28°C 东北风3级
结果是这样的
但不知道如何写?最好用shell写的,不想搞php或者python,那些需要环境太苛刻
大佬帮帮忙
按照3楼大佬的提示,用以下shell解决了
cat tq.txt|jq -r '.data[]'|awk -F ':' '{print$2}'|awk '{gsub(/["qing,yun<]/,"");print$0}'|awk '{printf "%s ", $0} END {printf "\n"}'|awk '{gsub(/级 /,"级\\n\\n");print$0}'|awk '{gsub(/ /,",");print$0}'|awk '{gsub(/ /,",");print$0}'|sed -n 's/,//p'|head
-c-2
新手写得不好,见笑了
结贴 |
|