-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

4
  • Determined how? Just always whatever comes after ls /live-nodes? Commented May 8, 2020 at 17:52
  • Also, are the linebreaks real/important, or can the whole thing just be coalesced into one line before doing any matching? Commented May 8, 2020 at 17:52
  • BTW, note that in general, you're expected to show what you tried and what specific problem you had while making that attempt in asking a question. Commented May 8, 2020 at 17:56
  • alwys comes after ls /live-nodes. line breaks are not real. its single string line Commented May 8, 2020 at 18:17

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.