我想要查看包含超过70%使用率的所有结果
输出示例:
{"ipaddr":"1.1.1.1","hostname":"host1.test.com","percentage":69,"dir":"/root"},
{"ipaddr":"1.1.1.1","hostname":"host1.test.com","percentage":79,"dir":"/oracle"},
{"ipaddr":"1.1.1.1","hostname":"host1.test.com","percentage":1,"dir":"/oradump"},
{"ipaddr":"1.1.1.1","hostname":"host1.test.com","percentage":90,"dir":"/archive"},
grep后的预期视图:
{"ipaddr":"1.1.1.1","hostname":"host1.test.com","percentage":79,"dir":"/oracle"},
{"ipaddr":"1.1.1.1","hostname":"host1.test.com","percentage":90,"dir":"/archive"},
答案 0 :(得分:7)
Awk更适合这里:
$ awk -F'[:,]' '$6>70' file
{"ipaddr":"1.1.1.1","hostname":"host1.test.com","percentage":79,"dir":"/oracle"},
{"ipaddr":"1.1.1.1","hostname":"host1.test.com","percentage":90,"dir":"/archive"},
答案 1 :(得分:3)
或者使用Perl:
$ perl -ne'print if /"percentage":([0-9]+),/ and $1 > 70'
(无需麻烦的分离计数)
答案 2 :(得分:3)
perl -F'[:,]' -ane 'print if $F[5]>70' file
答案 3 :(得分:0)
sed -n '/:[0]\?70,/d;/:[0-1]\?[7-9][0-9],/p' file