我有一个包含以下行的文件:
<polyline id="graph" points="0,287 100,470 200,509 300,459 400,471"/>
我需要提取以下值:
287 470 509 459 471
我目前正在使用此代码:
grep -oP '(?<=points=").*(?="/>)' "file.svg" | grep -oP '(?<=,)[[:digit:]]*'
我想用一个grep
来做到这一点,我尝试使用 (?:)
,没有成功。有什么建议吗?
最佳答案
sed 解决方案可以是这样的
$ sed -r '/points=/ s/[^,]+,?([0-9]*)/\1 /g' input
287 470 509 459 471
或者
更好的处理
$ sed -r '/points=/ s/.*points=("[^"]+").*/\1/g; s/[^,]+,?([0-9]*)/\1 /g' input
287 470 509 459 471
关于regex - 使用正则表达式解析 bash 中的分隔数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27078281/