1
Chyroc 2017-08-22 10:41:39 +08:00
echo '{"success":true,"data":{"request_5xx":1,"traffic_write":10866877,"average_traffix_write":426.43633010242,"average_traffic_read":429.33143664404,"traffic_read":10940653,"average_request_time":0.44471063102306,"total_count":25483,"request_3xx":0,"request_2xx":23981,"request_4xx":1501,"total_request_time":11332.561010361}}' | jq '. | {traffic_write: .data.traffic_write, request_4xx: .data.request_4xx}'
|
2
Chyroc 2017-08-22 10:42:06 +08:00
把 echo '{"success":true,"data":{"request_5xx":1,"traffic_write":10866877,"average_traffix_write":426.43633010242,"average_traffic_read":429.33143664404,"traffic_read":10940653,"average_request_time":0.44471063102306,"total_count":25483,"request_3xx":0,"request_2xx":23981,"request_4xx":1501,"total_request_time":11332.561010361}}' 换成 curl xxxx 即可
|
3
zhs227 2017-08-22 10:49:02 +08:00 1
|
4
krisbai OP @zhs227 嗯,这个工具确实蛮好用的,之前也在用,想请教下 我格式化出来的 带逗号,这个如何在获取参数的时候取消掉?
比如 :cat page.txt |jq .|grep request_4xx| cut -d ":" -f 2 得到的值 :1505, 想取消掉逗号 |
5
zhs227 2017-08-22 11:00:27 +08:00
试试 `jq --raw-output`
|
6
zhs227 2017-08-22 11:02:11 +08:00
用 jq 直接取字段,不要用 grep 处理。1 楼的答案。 比如 jq ".data.request_4xx"
|
7
NoAnyLove 2017-08-22 11:12:33 +08:00
话说直接用命令行下的 tr 和 grep 就行了啊,不需要安装额外的工具:
echo '{"request_5xx":1,"traffic_write":10866877,"average_traffix_write":426.43633010242,"average_traffic_read":429.33143664404,"traffic_read":10940653,"average_request_time":0.44471063102306,"total_count":25483,"request_3xx":0,"request_2xx":23981,"request_4xx":1501,"total_request_time":11332.561010361}' | tr -d '"' | grep -oP '(traffic_write:\d+)|(request_4xx:\d+)' |
12
ms2008 2017-08-22 15:29:26 +08:00
```
echo '{"success":true,"data":{"request_5xx":1,"traffic_write":10866877,"average_traffix_write":426.43633010242,"average_traffic_read":429.33143664404,"traffic_read":10940653,"average_request_time":0.44471063102306,"total_count":25483,"request_3xx":0,"request_2xx":23981,"request_4xx":1501,"total_request_time":11332.561010361}}' | python -mjson.tool ``` |
13
UnknownR 2017-08-22 20:32:04 +08:00 via iPhone
输出成 json 或者 xml 就可以了,都是数据存储格式,会自动调整的
|