一个自己的记录
计算出格式化后的json数据中,nowStepNum>2000的总和
用到了查找grep
、awk
分割-F
、awk
求和sum
,管道|
cat run | grep '"nowStepNum"' | awk -F': ' '{print $2}' | awk -F',' '{print $1}' | awk '{if ($1 > 2000) {print $1}}' | awk '{sum += $1};END {print sum}'
grep '"nowStepNum"'
:找到了"nowStepNum"这些行,_____"nowStepNum": 6167,
awk -F': ' '{print $2}'
:使用:_
冒号和空格分割,取第2个6167,
awk -F',' '{print $1}'
:使用,
逗号分割,取第1个6167
awk '{if ($1 > 2000) {print $1}}'
:取所有>2000的数
awk '{sum += $1};END {print sum}'
:求和
run文件
[
{
"donateId": "e65182ebb7ce48f2ad0bc4dc98885f40",
"donationCredit": 200,
"donationDate": "2021-09-02 23:41:07",
"donationDateDay": "2021-09-02",
"guid": "a343894bf5544df4898d1345b956fd79",
"nowStepNum": 6167,
"userId": "846d5795529845cd8481a5edcee2614a",
"wishId": "d85f17bc9a3c4462a8d22f227e1109e9",
"wishTitle": "xxxxxxxxxx"
},
{
"donateId": "80ed1113dffa4174a2b6723efb2828e8",
"donationCredit": 60,
"donationDate": "2021-09-02 00:00:25",
"donationDateDay": "2021-09-02",
"guid": "1de23200865243f291df65db32b35a5c",
"nowStepNum": 4,
"userId": "846d5795529845cd8481a5edcee2614a",
"wishId": "3b0e65d098f6427d8869f1d82e4f922d",
"wishTitle": "xxxxxxxxxx"
},
{
"donateId": "196defe9523d405e915d64b73e6c107b",
"donationCredit": 200,
"donationDate": "2021-09-01 20:52:12",
"donationDateDay": "2021-09-01",
"guid": "1dd02519c4564a8587c6f3c4a080ca9e",
"nowStepNum": 5975,
"userId": "846d5795529845cd8481a5edcee2614a",
"wishId": "d85f17bc9a3c4462a8d22f227e1109e9",
"wishTitle": "xxxxxxxxxx"
}
]