01 获取字符串所在的行数
方式一:用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 获取字符串中字符所在的位置
方式一:用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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
是否也想过要入Linux这个坑?我刚入,并且很O(∩_∩)O~ !(适合Linux新手)
Win知识 - 程序是怎样跑起来的——系统调用和高级编程语言的移植性
MPS DC-DC Designer帮你搞定DC-DC电路设计
网友评论