Getting specific strings from output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting specific strings from output
# 1  
Old 02-04-2013
Getting specific strings from output

so i have the following string:

Code:
{"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:
Code:
"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
# 2  
Old 02-04-2013
I guess
Code:
$ 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 ?
# 3  
Old 02-04-2013
Quote:
Originally Posted by RudiC
I guess
Code:
$ 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 Smilie
# 4  
Old 02-04-2013
Code:
$ grep -o '"queue_totals":{"messages":[0-9]*,"messages_ready":[0-9]*,"messages_unacknowledged":[0-9]*' file

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using find to output list of files with specific strings

This is my problem, I am using the following code to extract the file names with specific strings 0.01: find ./ -name "*.txt" -exec grep -H '0.01' {} + It works wonders with a small sample. However, when I use it in a real scenario it produces an empty file -even though I am sure there are... (11 Replies)
Discussion started by: Xterra
11 Replies

2. Shell Programming and Scripting

How to extract fields containing specific strings?

Hello I have a log file with thousands of lines like below Sep 21 13:02:52 lnxtst01 kernel: New TCP in: IN=eth0 OUT= MAC=00:1a:4b:50:b7:32:00:08:e3:ff:fc:04:08:00 SRC=10.184.46.4 DST=10.162.139.21 LEN=60 TOS=0x00 PREC=0x00 TTL=59 ID=52961 DF PROTO=TCP SPT=55688 DPT=22 WINDOW=5840 RES=0x00 SYN... (3 Replies)
Discussion started by: magnus29
3 Replies

3. UNIX for Dummies Questions & Answers

Delete specific strings in a file

Hi, My file has a numerous sttrings.I want to retain those strings which start with stt and delete entries with >C For eg: my infile is >C4603985... (7 Replies)
Discussion started by: sa@@
7 Replies

4. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

5. UNIX for Dummies Questions & Answers

Finding specific series of strings or characters

After spending sometime playing around with my script I just cannot get it to do what I want. So I decided to ask. My file looks something like this: I am using the following code to extract sequences that contain dashes awk '/^>/{id=$0;next}{if (match($1,"-")) print id "\n" $0}' infile ... (17 Replies)
Discussion started by: Xterra
17 Replies

6. Shell Programming and Scripting

output strings to specific positions in a file

Been searching for about 3 hours for similar functionality that I can get examples of how to output text from variables into certain locations in a file. I would like to incorporate this into a script. I have not been able to find a command example that does it all in one method. I find part of... (1 Reply)
Discussion started by: bennu_500
1 Replies

7. Shell Programming and Scripting

print specific strings only

Hello, I have a file like this.. 2 168611167 STK39 STK39 --- 27347 "serine threonine kinase 39 (STE20/SPS1 homolog, yeast)" YES SNP_A-2086192 rs16854601 0.001558882 6 13670256 SIRT5 /// RPS4X SIRT5 --- 23408 /// 6191 "sirtuin (silent mating type... (5 Replies)
Discussion started by: genehunter
5 Replies

8. Shell Programming and Scripting

Remove specific strings from certain fields

I'm working with a set of files where I'm trying to remove a set of characters from specific fields. The files are comma-delimited, and the characters I want to remove include: - open parentheses - ( - close parentheses - ) - space followed by a dollar sign - $ I don't want to remove every... (1 Reply)
Discussion started by: HLee1981
1 Replies

9. Shell Programming and Scripting

Search for multiple strings in specific position

Hi, I need to search for some strings in specific positions in a file. If the strings: "foo1", "foo2" or "foo3" is on position 266 or position 288 in a file i want the whole line printed. Any idea how to do it? (5 Replies)
Discussion started by: HugoH
5 Replies

10. Shell Programming and Scripting

delete strings till specific string

Hello i want to know a way so i can delete all the strings in file from the begning till a specific string (1 Reply)
Discussion started by: modcan
1 Replies
Login or Register to Ask a Question