Bash 如何在SHELL中使用字符串匹配条件从字符串中提取子字符串
我必须从中提取一个子字符串Bash 如何在SHELL中使用字符串匹配条件从字符串中提取子字符串,bash,shell,Bash,Shell,我必须从中提取一个子字符串 - 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] add
- 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]
要提取的子字符串为
[rn3-gcs02.rno.foo.com:8985_solr,rn3-
gcsb.rno.foo.com:8985_solr]
它是一个动态子字符串,可以有2个或更多元素
re='ls /live_nodes (\[[^]]+\])'
[[ $s =~ $re ]] && echo "${BASH_REMATCH[1]}"
…通过您在$s
中的输入发射:
[rn3-gcs02.rno.foo.com:8985\u solr,rn3-
gcsb.rno.foo.com:8985_solr]
如何确定?总是在ls/live nodes
之后出现什么?此外,换行符是真实的/重要的,还是在进行任何匹配之前,整个事情可以合并成一行?顺便说一句,请注意,通常,在尝试提问时,您需要显示您尝试了什么以及遇到了什么具体问题。alwys位于ls/live节点之后。换行符不是真的。它的单线