Page 1 of 1

Help needed with "awk" or "sed" to separate output

Posted: 2010/05/31 14:43:36
by torontob123
Hi Guys,

Here is an output of a command run on CentOS 5.4 with Asterisk installed:

[code]
root@pbx:~ $ asterisk -rx "sip show channels"
Peer User/ANR Call ID Seq (Tx/Rx) Format Hold Last Message
192.168.0.100 (None) f2bee81d79e 00101/01638 0x0 (nothing) No Rx: REGISTER
211.211.11.11 4164005000 769124927da 00101/00102 0x4 (ulaw) No Rx: ACK
192.168.0.100 502 a6e594f37ef 00101/21193 0x4 (ulaw) No Rx: ACK
3 active SIP channels
[/code]
From above I want to simply segregate the IP address and the format which is ulaw. Those two means a call is in progress. So, I want to basically count how many calls are in progress at this time.

Here is what I have been fiddling with to get it working but it doesn't seem so:

[code]
[root@ip-10-251-123-3 ~]# gawk -F: '{ print $1 $5 }' | asterisk -rx "sip show channels"
Peer User/ANR Call ID Format Hold Last Message
111.111.111.111 (None) 326fd0be2333b62 0x0 (nothing) No Rx: REGISTER
1 active SIP dialogs
[/code]
So, the above doesn't actually spit out "111.111.111.111" and "nothing" which it should. I am sure I am not using awk in the right away. Any help is appreciated.

Thanks,
Bruce

[Moderator edited to insert [i]code[/i] tags to improve readability.]

Help needed with "awk" or "sed" to separate output

Posted: 2010/05/31 14:55:55
by AlanBartlett
Please try --

[code]
[b]asterisk -rx "sip show channels" | awk 'NR > 1 { print $1"\t"$5 }'[/b]
[/code]
Now if you just want to count occurrences of the string "(ulaw)" in the output of the [i]asterisk -rx "sip show channels"[/i] command, why not keep it simple? Specifically --

[code]
[b]asterisk -rx "sip show channels" | grep -c "(ulaw)"[/b]
[/code]
Let's combine the two --

[code]
[b]asterisk -rx "sip show channels" | awk '/ulaw/ { print $1 }'[/b]
[/code]
Something like the following my be more like what you require --

[code]
[b]asterisk -rx "sip show channels" | awk '/ulaw/ { print $1 } END { print $0 }'[/b]
[/code]
Finally --

[code]
[b]asterisk -rx "sip show channels" | awk '/ulaw/ { print $1 } END { print $1 }'[/b]
[/code]

Re: Help needed with "awk" or "sed" to separate output

Posted: 2010/05/31 20:37:49
by torontob123
Thank you very much. Amazing details. Seems like the simple count will just help me.

You have made my day :-)

So, thank you again.

-Bruce

Re: Help needed with "awk" or "sed" to separate output

Posted: 2010/06/01 10:52:07
by AlanBartlett
[quote]
Thank you very much. Amazing details.
[/quote]
You're welcome. :-)

[And, whilst wearing my Moderator's hat, I'll mention that this thread has been moved to [i]Social[/i] as it does not contain a specific [i]CentOS[/i] support request. ;-) ]