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

A 5 star hangout for overworked and underpaid system admins.

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

Postby torontob123 » 2010/05/31 14:43:36

Hi Guys,

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

Code: Select all
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

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: Select all
[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

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 code tags to improve readability.]
torontob123
 
Posts: 95
Joined: 2009/11/30 20:21:14

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

Postby AlanBartlett » 2010/05/31 14:55:55

Please try --

Code: Select all
[b]asterisk -rx "sip show channels" | awk 'NR > 1 { print $1"\t"$5 }'[/b]

Now if you just want to count occurrences of the string "(ulaw)" in the output of the asterisk -rx "sip show channels" command, why not keep it simple? Specifically --

Code: Select all
[b]asterisk -rx "sip show channels" | grep -c "(ulaw)"[/b]

Let's combine the two --

Code: Select all
[b]asterisk -rx "sip show channels" |  awk '/ulaw/ { print $1 }'[/b]

Something like the following my be more like what you require --

Code: Select all
[b]asterisk -rx "sip show channels" | awk '/ulaw/ { print $1 } END { print $0 }'[/b]

Finally --

Code: Select all
[b]asterisk -rx "sip show channels" | awk '/ulaw/ { print $1 } END { print $1 }'[/b]
User avatar
AlanBartlett
Forum Moderator
 
Posts: 8975
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk

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

Postby torontob123 » 2010/05/31 20:37:49

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
torontob123
 
Posts: 95
Joined: 2009/11/30 20:21:14

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

Postby AlanBartlett » 2010/06/01 10:52:07

Thank you very much. Amazing details.

You're welcome. :-)

[And, whilst wearing my Moderator's hat, I'll mention that this thread has been moved to Social as it does not contain a specific CentOS support request. ;-) ]
User avatar
AlanBartlett
Forum Moderator
 
Posts: 8975
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk


Return to CentOS Social

Who is online

Users browsing this forum: No registered users and 0 guests