-1

I have to extract a substring from this.

- Session establishment complete on server localhost/127.0.0.1:2183, sessionid = 
   0x1000c22ff510020, negotiated timeout = 120000 WATCHER:: WatchedEvent state:SyncConnected 
   type:None path:null [zk: localhost:2183(CONNECTED) 0] addauth digest super:testing [zk: 
   localhost:2183(CONNECTED) 1] ls /live_nodes [rn3-gcs02.rno.foo.com:8985_solr, rn3- 
   gcsb.rno.foo.com:8985_solr] [zk: localhost:2183(CONNECTED) 2]

The substring to be extracted is

[rn3-gcs02.rno.foo.com:8985_solr, rn3- gcsb.rno.foo.com:8985_solr]

it's a dynamic substring which can have 2 or more elements

Telen
  • 155
  • 1
  • 3
  • 15

1 Answers1

1
re='ls /live_nodes (\[[^]]+\])'
[[ $s =~ $re ]] && echo "${BASH_REMATCH[1]}"

...emits, with your input in $s:

[rn3-gcs02.rno.foo.com:8985_solr, rn3-
   gcsb.rno.foo.com:8985_solr]
Charles Duffy
  • 257,635
  • 38
  • 339
  • 400