方法1:
#!/bin/ksh
var="A12345A67890123A45"
tmp=$(echo $var | sed 's/(.*A)(.*)/1/')
echo ${#tmp}
$test.sh
16
方法2:
方法3:
rindex.sh代码:
#!/bin/bash
strToCheck=$1;
charToSearch=$2;
let pos=`echo "$strToCheck" | awk -F ''$charToSearch'' '{printf "%d", length($0)-length($NF)}'`
echo "char $charToSearch lastpos is: $pos"
例子:
顺序查找,可以用: