[root@localhost ~]# cat a.txt abcdeabcde [root@localhost ~]# cat 1.awk function rindex(str,findstr,k,ns,nf) { ns=length(str) nf=length(findstr) for (k=ns-nf+1;k>=1;k--) if (substr(str, k, nf) == findstr) return k return 0 } {print rindex($0,"cd")} [root@localhost ~]# awk -f 1.awk a.txt 8
转载于:https://blog.51cto.com/sndapk/1202020