Number of greps between colon and comma

I want to grep all results that contain more than 70 percent of usage

Output Example:

{"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"}, 

Expected view after 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"}, 
+4
source share
4 answers

Awk is more suitable here:

 $ 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"}, 
+7
source

Or with Perl:

 $ perl -ne'print if /"percentage":([0-9]+),/ and $1 > 70' 

(no fragmentation needed)

+3
source
 perl -F'[:,]' -ane 'print if $F[5]>70' file 
+3
source

GNU sed

 sed -n '/:[0]\?70,/d;/:[0-1]\?[7-9][0-9],/p' file 
0
source

Source: https://habr.com/ru/post/1483777/


All Articles