Getting specific strings from output

so i have the following string:

{"management_version":"3.0.0","statistics_level":"fine","exchange_types":[{"name":"topic","description":"AMQP topic exchange, as per the AMQP specification","enabled":true},{"name":"fanout","description":"AMQP fanout exchange, as per the AMQP specification","enabled":true},{"name":"direct","description":"AMQP direct exchange, as per the AMQP specification","enabled":true},{"name":"headers","description":"AMQP headers exchange, 
as per the AMQP specification","enabled":true}],"jabalpatelmq_version":"3.0.0","erlang_version":"R14B04","message_stats":[],"queue_totals":{"messages":0,"messages_ready":0,"messages_unacknowledged":0,"messages_details":{"rate":0,"interval":319135987,"last_event":1359988174957},"messages_ready_details":{"rate":0,"interval":319135987,"last_event":1359988174957},"messages_unacknowledged_details":{"rate":0,"interval":319135987,"last_event":1359988174957}},"object_totals":{"consumers":0,"queues":1,"exchanges":8,"connections":0,"channels":0},"node":"jabalpatel@jabalpatelmq-beta-vm-01","statistics_db_node":"jabalpatel@jabalpatelmq-beta-vm-01","listeners":[{"node":"jabalpatel@jabalpatelmq-beta-vm-01","protocol":"amqp","ip_address":"0.0.0.0","port":5672},
{"node":"jabalpatel@jabalpatelmq-beta-vm-02","protocol":"amqp","ip_address":"0.0.0.0","port":5672},{"node":"jabalpatel@jabalpatelmq-beta-vm-03","protocol":"amqp","ip_address":"0.0.0.0","port":5672}],
"contexts":[{"node":"jabalpatel@jabalpatelmq-beta-vm-01","description":"JabalpatelMQ Management","path":"/","port":15672},{"node":"jabalpatel@jabalpatelmq-beta-vm-02","description":"JabalpatelMQ Management","path":"/","port":15672},
{"node":"jabalpatel@jabalpatelmq-beta-vm-03","description":"JabalpatelMQ Management","path":"/","port":15672},{"node":"jabalpatel@jabalpatelmq-beta-vm-01",
"description":"Redirect to port 15672","path":"/","port":55672,"ignore_in_use":true},{"node":"jabalpatel@jabalpatelmq-beta-vm-02","description":"Redirect to port 15672","path":"/","port":55672,"ignore_in_use":true},{"node":"jabalpatel@jabalpatelmq-beta-vm-03","description":"Redirect to port 15672","path":"/","port":55672,"ignore_in_use":true}]}[root@nagios-04 ~]#

i want to echo this output and grep out the following string:

"queue_totals":{"messages":0,"messages_ready":0,"messages_unacknowledged":0

what command can do this? i know awk can. but i'm not a awk specialist...not yet.

os: linux/sun/hpux

I guess

$ grep -o '"queue_totals":{"messages":0,"messages_ready":0,"messages_unacknowledged":0' file
"queue_totals":{"messages":0,"messages_ready":0,"messages_unacknowledged":0

is not what you want. How do you identify the string to be extracted ?

the values of "0" will change. and they need to be calculated (for each one) to make sure they're not over a certain value. say 200. so that grep -o may not work. but i think we're close here :slight_smile:

$ grep -o '"queue_totals":{"messages":[0-9]*,"messages_ready":[0-9]*,"messages_unacknowledged":[0-9]*' file
1 Like