我想知道每天每小时提交的次数。使用下面的命令,我能够获得json格式的输出。但是,我想知道是否可以使用命令行将键添加到json格式的值中?
curl https://api.github.com/repos/test/myrepo/stats/punch_card
当前产出:
[
0,
2,
32
]
预期产出:
[
day: 0,
hour: 2,
commits: 32
]
发布于 2016-10-02 09:14:22
由于您没有指定“命令行”以外的任何内容,所以我假设您需要一个bash
-based解决方案。这个简单的脚本(虽然有点难看)可以做您想做的事情,同时保持缩进(除了总体响应的结束方括号之外):
#!/bin/bash
resp=$(curl https://api.github.com/repos/test/myrepo/stats/punch_card)
nextPref=""
for val in $resp
do
echo "$nextPref $val"
if [[ $val == "[" && $nextPref == "" ]]
then
nextPref=" "
elif [[ $val == "[" && $nextPref == " " ]]
then
nextPref=" day:"
elif [[ $nextPref == " day:" ]]
then
nextPref=" hour:"
elif [[ $nextPref == " hour:" ]]
then
nextPref=" commits:"
elif [[ $nextPref == " commits:" ]]
then
nextPref=" "
fi
done
https://stackoverflow.com/questions/39819329
复制相似问题