-1

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
Clients:
 /182.33.12.56:51397[1](queued=0,recved=43168,sent=43168)
 /182.33.12.36:51915[1](queued=0,recved=1305948,sent=1305948)
 /182.33.12.60:43528[1](queued=0,recved=793,sent=793)
 /182.33.12.60:40151[1](queued=0,recved=5990,sent=5990)
 /182.33.12.35:52973[1](queued=0,recved=117840,sent=117840)
 /182.33.12.56:53533[1](queued=0,recved=76252,sent=76489)


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

 182.33.12.56:51397
 182.33.12.36:51915
 182.33.12.60:43528
 182.33.12.60:40151
 182.33.12.35:52973
 182.33.12.56:53533

so we try this

echo stat | nc localhost  2181 | grep -E  "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | awk '{print $1}'
/182.33.12.56:51397[1](queued=0,recved=43282,sent=43282)
/182.33.12.36:51915[1](queued=0,recved=1305988,sent=1305988)
/182.33.12.60:43528[1](queued=0,recved=815,sent=815)
/182.33.12.35:53110[0](queued=0,recved=1,sent=0)
/182.33.12.60:40151[1](queued=0,recved=6013,sent=6013)
/182.33.12.35:52973[1](queued=0,recved=117857,sent=117857)

but without success

2

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 at 17:12
  • the new update not print anything – yael Jan 17 at 17:14
  • now its show the right results – yael Jan 17 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 at 17:22
  • OK. Switch to PCRE and removal of the brackets around the dot did it then. – ozzy Jan 17 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.