by the following command we can identify which ip are using port 2181 and the relevant port

echo stat | nc localhost  2181
Zookeeper version: 3.4.6-91--1, built on 01/04/2018 10:34 GMT

Latency min/avg/max: 0/0/329
Received: 6097607
Sent: 6324062
Connections: 14
Outstanding: 0
Zxid: 0x50027d362
Mode: follower
Node count: 90630

what I want is to capture only the ip's with there ports

so the expected output should be

so we try this

echo stat | nc localhost  2181 | grep -E  "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | awk '{print $1}'

but without success


Try it with the -o option to grep:

echo stat | nc localhost  2181 | grep -oP  "([0-9]{1,3}\.){3}[0-9]{1,3}:\d+" 

This should print only the part of the line matching the regex, instead of the entire line. And it also obviates the need for an additional ‘awk’ invocation.

  • this print only the ips and we want the ips:port ( see my expected results – yael Jan 17 '19 at 17:12
  • the new update not print anything – yael Jan 17 '19 at 17:14
  • now its show the right results – yael Jan 17 '19 at 17:20
  • odd, i’m on my phone, so I can’t verify, but I don’t immediately see why it wouldn’t work. – ozzy Jan 17 '19 at 17:22
  • OK. Switch to PCRE and removal of the brackets around the dot did it then. – ozzy Jan 17 '19 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.