Try this:
grep 'client connection' test.txt | awk -F'[/\\]]' '{print $2}'
Test case
test.txt
---------
abcd
.....client connection.....remote=/10.20.30.40]].......
abcs
.....client connection.....remote=/11.20.30.40]].......
.....client connection.....remote=/12.20.30.40]].......
Result
10.20.30.40
11.20.30.40
12.20.30.40
Explanation
grep
will shortlist the results to only lines matching client connection. awk
uses -F
flag for delimiter to split text. We ask awk
to use /
and ]
delimiters to split text. In order to use more than one delimiter, we place the delimiters in [
and ]
. For example, to split text by =
and :
, we'd do [=:]
.
However, in our case, one of the delimiters is ]
since my intent is to extract IP specifically from /x.x.x.x]
by spitting the text with /
and ]
. So we escape it ]
. The IP is the 2nd item from the splitting.