echo "this is a test:foo,bar,baz']" | grep -o -E "test:.*" | awk -F: '{ print $2 }'
foo,bar,baz']
我最后打印']
,如何只打印字符和普通字,没有别的,在这种情况下我只需要提取foo,bar,baz
答案 0 :(得分:0)
您可以使用单个awk
:
echo "this is a test:foo,bar,baz']" | awk -F 'test:' '{sub(/[^,[:alnum:]].*/, "", $2); print $2}'
foo,bar,baz
或者,您可以使用单个sed
:
echo "this is a test:foo,bar,baz']" | sed 's/.*test://; s/[^,[:alnum:]].*//'
foo,bar,baz
答案 1 :(得分:0)
echo "this is a test:foo,bar,baz']"| awk -F: '{sub(/baz../,"baz"); print $2}'
输出
FOO,酒吧,巴兹
答案 2 :(得分:0)
使用gnu grep 珍珠正则表达式
$ echo "this is a test:foo,bar,baz']" | grep -oP "(?<=test:)(\w,*)+"
foo,bar,baz