使用Shell脚本提取“ [和]”之间的值

时间:2019-01-11 11:30:24

标签: regex bash shell

使用shell脚本在“ [和]”之间提取值

"[""sometext1"", ""sometext2"", ""sometext3""]"

3 个答案:

答案 0 :(得分:0)

echo '"[""sometext1"", ""sometext2"", ""sometext3""]"'|cut -d "[" -f2 | cut -d "]" -f1

答案 1 :(得分:0)

转义第一个'['

echo '"[""sometext1"", ""sometext2"", ""sometext3""]"'|
   sed -r 's/"\[(.*)]"/\1/'

答案 2 :(得分:0)

使用Perl

$ echo '"[""sometext1"", ""sometext2"", ""sometext3""]"'
"[""sometext1"", ""sometext2"", ""sometext3""]"

$ echo '"[""sometext1"", ""sometext2"", ""sometext3""]"' | perl -ne ' m/\[(.*)\]/ and print $1 '
""sometext1"", ""sometext2"", ""sometext3""
$