文字列の数と位置を取得するためのシェル
文字列を取得するには、行01の数が位置しています
方法1:使用grep -n
[root@root]# cat test
apple
bit
create
delect
exe
flow
good
[root@root]# cat test | grep -n exe
5:exe
[root@root]# cat test | grep -n exe | awk -F ":" '{print $1}'
5
第二の方法:とsed -n '/查询的字符串/=' 文件
[root@root]# cat test
apple
bit
create
delect
exe
flow
good
[root@root]#
[root@root]# sed -n '/exe/=' test
5
位置の文字の文字列内の02のget位置
一つの方法:とawk -F
とwc -c
構図
[root@root]# echo 'uellevcmpottcap' | awk -F 'ott' '{print $1}';
uellevcmp
[root@root]# echo 'uellevcmpottcap' | awk -F 'ott' '{print $1}' | wc -c
10
第二の方法:とawk 'BEGIN{print index("'${str}'","'${str1}'") }'
[root@root]# str='uellevcmpottcap';str1='ott';awk 'BEGIN{print index("'${str}'","'${str1}'") }'
10