我有以下文字:
{{{VSER}}} is doing well. He went to {{{MARKET}}}.
It is very useful {{{RESOURCE}}}
我想解析{{{
和}}}
之间的字符串运行脚本echo $TEXT | somescript
,然后结果应为:
VSER
MARKET
RESOURCE
尝试使用sed:
echo $TEXT | sed 's/.*{{{ //' | sed # /}}}.*$//'
但是,它会返回{{{VSER
,甚至不返回VSER
。
答案 0 :(得分:2)
实测!
echo $TEXT | awk -vRS="}}}" -vFS="{{{" '{print $2}'
感谢您的时间
答案 1 :(得分:0)
GNU grep
有PCRE可用:
$ TEXT='{{{VSER 123}}} is doing well. He went to {{{MARKET}}}.
It is very useful {{{RESOURCE}}}'
$ echo $TEXT | grep -oP '\{\{\{\K.*?(?=}}})'
VSER 123
MARKET
RESOURCE
$ echo "$TEXT" | grep -oP '\{\{\{\K.*?(?=}}})'
VSER 123
MARKET
RESOURCE
$ # with perl
$ echo "$TEXT" | perl -lne 'print join "\n", /\{\{\{\K.*?(?=}}})/g'
VSER 123
MARKET
RESOURCE