Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep numbers between colon and comma

Tags:

grep

bash

sed

awk

perl

I want to grep all results which contain over 70 percent of usage

Example of output:

{"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 the 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"},
like image 460
Kalin Borisov Avatar asked Dec 11 '22 14:12

Kalin Borisov


1 Answers

Awk is more suited 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"},
like image 168
Chris Seymour Avatar answered Dec 31 '22 00:12

Chris Seymour