user3310052 user3310052 - 3 months ago 12
Bash Question

get specific sub-strings in a long string

I have a long string which but I am only interested in two variables

state
and
callee_contact
and their values.

dialog:: hash=2089:3329 state:: 4 ref_count:: 2 timestart:: 1471200133 timeout:: 130932077 callid:: TVO3l_3-n-gAYdlXqlFHGg.. from_uri:: sip:1010@192.168.10.5;transport=UDP from_tag:: c279ef54 caller_contact:: sip:1010@192.168.10.10:58055;transport=UDP caller_cseq:: 1 caller_route_set:: caller_bind_addr:: udp:192.168.10.5:5060 callee_bind_addr:: udp:192.168.10.5:5060 to_uri:: sip:4646644@192.168.10.5;transport=UDP to_tag:: yBr2aQBNHSZge callee_contact:: sip:4646644@192.168.10.10:5080;transport=udp callee_cseq:: 0 callee_route_set:: dialog:: hash=3480:8766 state:: 2 ref_count:: 2 timestart:: 1471200092 timeout:: 130932077 callid:: --8J4085lgGwUqLlr0LUEw.. from_uri:: sip:1010@192.168.10.5;transport=UDP from_tag:: 7d327878 caller_contact:: sip:1010@192.168.10.2:58055;transport=UDP caller_cseq:: 2 caller_route_set:: caller_bind_addr:: udp:192.168.10.5:5060 callee_bind_addr:: udp:192.168.10.5:5060 to_uri:: sip:4646644@192.168.10.5;transport=UDP to_tag:: X2y98UtHmg9Xj callee_contact:: sip:4646644@192.168.10.20:5080;transport=udp callee_cseq:: 0 callee_route_set::

Result should look like below.

state:: 4 callee_contact:: sip:4646644@192.168.10.10:5080;transport=udp state:: 2 callee_contact:: sip:4646644@192.168.10.20:5080;transport=udp

Any help is much appreciated.
Thanks.

Answer
grep -o -e "state:: [^ ]*" -e "callee_contact:: [^ ]*"