我正在尝试找到一个可以给我 [ 和 ] 之间的文本的 Linux 命令。我尝试了标准的 grep 和 sed 但没有任何帮助。假设文本在日志中。喜欢-
The list of tables you have currently [apple, pineapple, wood-apple]
我只想要这个文字[苹果,菠萝,木苹果]
目前已尝试过
到目前为止,他们都没有提供帮助。谁能帮忙提供正确的命令来帮助我
$ echo "$logs" | grep -o '\[.*]'
[apple, pineapple, wood-apple]
$ echo "$logs" | sed -n 's/.*\(\[.*]\).*/\1/p'
[apple, pineapple, wood-apple]
$ echo "$logs" | awk -F'[][]' '{print "[" $2 "]"}'
[apple, pineapple, wood-apple]