timonvlad
timonvlad

Reputation: 1056

sed substring from incoming packet

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

Answers (3)

MeSee
MeSee

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

Zombo
Zombo

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
  • change : to \r
  • change @ to \n
  • print up to first newline
  • delete pattern space

Upvotes: 1

Steve
Steve

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

Related Questions