Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从以下字符串中获取 bash 中的数字。
$qry2)); 275-->275而不是2275
$qry2)); 275
275
2275
$qry1)) { 147-->147而不是1147
$qry1)) { 147
147
1147
那么获取最后一个整数的代码是什么?
如果可以使用grep,可以尝试:
grep
echo '$qry2)); 275' | grep -o '[0-9]*$'
使用 anawk您可以获得最后一个字段:
awk
awk '{ print $NF }'
使用sed:
sed
sed 's/^.*[^0-9]\([0-9][0-9]*$\)/\1/'
查找行首,任意数量的字符,后跟一个非数字和一串数字到行尾;用数字字符串替换它。