Reputation: 1056
String I want to sed i get from incoming sniffered packet... I want to get substring from string, f.e.
INVITE sip:[email protected]:5060 SIP/2.0
Using sed
I would like to extract substring.
Substring is between sip:
and @
... So for my example, I need to get
18455845013
Upvotes: 3
Views: 209
Reputation: 469
Keep the bit between the : and @.
sed 's/.*:\(.*\)@.*/\1/'
Example:
$ echo "INVITE sip:[email protected]:5060 SIP/2.0" | sed 's/.*:\(.*\)@.*/\1/'
18455845013
Upvotes: 1
Reputation: 1
Input file
$ cat foo.txt
INVITE sip:[email protected]:5060 SIP/2.0
Result
$ sed 'y/:@/\r\n/;P;d' foo.txt
18455845013
:
to \r
@
to \n
Upvotes: 1
Reputation: 54512
If your grep
supports the -P
flag, try:
grep -oP '(?<=sip:)[^@]*'
Results:
18455845013
Else, use sed
like Steven Penny has done. HTH.
Upvotes: 1