我试图在BusyBox上使用正则表达式从2个字符串之间提取一个字符串。我已经能够在本地完成
extract_string=$(echo $content | grep -P '(?<=CURRENT_VERSION ")(.*)(?=")' -o)
但是可悲的是,此BusyBox版本的grep
命令不支持该-P
选项。我可以使用sed
,awk
和grep
。
细绳: #define CURRENT_VERSION "1.0.0.2" some other random text
输出: 1.0.0.2
有人知道我可以做到这一点的另一种方法吗?
操作系统: Kernel 2.6.x
实用工具:来自busybox 1.2x
与sed
:
extract_string=$(
printf '%s\n' "$content" |
sed -n 's/.*CURRENT_VERSION "\([^"]*\).*/\1/p'
)
与awk
:
extract_string=$(
printf '%s\n' "$content" |
awk -F'"' '/CURRENT_VERSION/{ print $2 }'
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句