获取长字符串

时间:2016-08-14 19:41:00

标签: linux bash shell

我有一个长字符串,但我只对两个变量statecallee_contact以及它们的值感兴趣。

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 ::

结果应如下所示。

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

非常感谢任何帮助。 感谢。

1 个答案:

答案 0 :(得分:2)

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