sed remembering part of pattern using \1 concept

I am using this concept to fetch value of IP address after node= in this line of csv text:

a="Measurement:,OutInviteResponseTime,Sessionid=1860700092328051458,node=67.178.40.168,nodeName=abcd,protocol=GK,25523000"

echo $a | sed 's/.*node=\(.*\).*/\1/'

But this outputs:

67.178.40.168,nodeName=CHCIILNQPS1_Area4_67.178.40.168,protocol=SIP,25523000

I only want output till 67.178.40.168, that is, text between node= and comma (,).

Note: I can't use AWK on this because the columns are variable in input.

Try this...

echo $a | sed 's/\(.*\)node=\(.*\),nodeName\(.*\)/node=\2,/'

I want a solution that has no dependency on other columns, because as i said that my input string will have variable columns.

Try a regular expression after node=, like
[0-9][0-9].[0-9]..and so on.
try first yourself.

Try this:

sed 's/.*node=\([^,*]*\).*/\1/'

Thanks Franklin52

Can you please explain the logic? I didn't quite understand the use of square brackets.

echo "a="Measurement:,OutInviteResponseTime,Sessionid=1860700092328051458,node=67.178.40.168,nodeName=abcd ,protocol=GK,25523000"" | cut -d ',' -f 4 | cut -d '=' -f2

code :-

sed 's/.*\=\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/g'

Also this below will work

sed 's/.*node=\([^a-zA-Z,]*\).*/\1/g'

BR

Thanks to all for the replies.
The solutions given by Franklin and ahmad(second one) is most suited to me, since i need a generic expression, not something that is specific (eg. IP address only).

sed 's/.*node=\([^,*]*\).*/\1/'

Works well.

But i didn't quite get the logic of this code. Hoping to get an explanation :slight_smile:

Explanation:-

sed '
/.*                           #means any string [numbers or char] strings (0 or   more times)
node=                      #means node=

\([^,*]*\) :-
 \(\)                        # means remember 
[^,*]                      # means not "," (0 or more times)
*                            # (repeated 0 or more times)

\1                         # means to print what he had remember

This \([^,*]*\) means: select everything in a portion after .*node= without a comma.

Regards