当前位置:网站首页>shell统计某个字符串最后一次出现的位置之前的所有字符串
shell统计某个字符串最后一次出现的位置之前的所有字符串
2022-06-30 02:51:00 【雅冰石】
需求:
我想统计某个ip所属网段。
示例:
有一台服务器ip是192.168.144.249,我想统计到192.168.144这个网段。
方法一:
strToCheck='192.168.144.251'
letpos=`echo "$strToCheck" | cut -d '.' -f 1,2,3`
echo $letpos
结果为192.168.144
方法二较复杂些:
#先统计最后一个.在哪个位置
strToCheck='192.168.144.249'
charToSearch='.'
letpos=`echo "$strToCheck" | awk -F ''$charToSearch'' '{printf "%d", length($0)-length($NF)}'`
#再统计该位置前面的字符串
echo ${strToCheck:0:$letpos}
结果192.168.144.
--本篇文章参考自:Shell脚本实现查找字符串中某字符最后出现的位置 / 张生荣
边栏推荐
- Which is a good foreign exchange trading platform? Is it safe to have regulated funds?
- High paid programmers & interview questions series 63: talk about the differences between sleep (), yield (), join (), and wait ()
- 重磅来袭--UE5的开源数字孪生解决方案
- Jupyter notebook显示k线图集合
- How to prevent phishing emails? S/mime mail certificate
- 怎么使用Vant实现数据分页和下拉加载
- 迅為恩智浦iTOP-IMX6開發平臺
- NPDP产品经理国际认证考试报名有什么要求?
- How does native JS generate Jiugong lattice
- Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla
猜你喜欢

How to use redis to realize the like function

论文回顾:Playful Palette: An Interactive Parametric Color Mixer for Artists

Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)

Unity timeline data binding

How to switch ipykernel to a different CONDA virtual environment in jupyterlab?
![[论]【DSTG】Dynamic SpatiotemporalGraph Convolutional Neural Networks for Traffic Data Imputation](/img/c3/f9d6399c931a006ca295bb1e3ac427.png)
[论]【DSTG】Dynamic SpatiotemporalGraph Convolutional Neural Networks for Traffic Data Imputation

IBM websphere通道联通搭建和测试

Pytorch学习(二)

Unity3d ugui force refresh of layout components

Shenzhen CPDA Data Analyst Certification in July 2022
随机推荐
unity的text首列有标点符号咋办
Interrupt operation: abortcontroller learning notes
High paid programmers & interview questions series 63: talk about the differences between sleep (), yield (), join (), and wait ()
JMeter obtains cookies across thread groups or JMeter thread groups share cookies
福利抽奖 | 开源企业级监控Zabbix6.0都有哪些亮点
Cmake tutorial series -04- compiling related functions
2022护网行动在即,关于护网的那些事儿
Global and Chinese markets for light cargo conveyors 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of subscription revenue management software 2022-2028: Research Report on technology, participants, trends, market size and share
[论]【DSTG】Dynamic SpatiotemporalGraph Convolutional Neural Networks for Traffic Data Imputation
打造創客教育中精湛技藝
threejs 镜子案例Reflector 创建镜子+房子搭建+小球移动
并发请求下如何防重复提交
Differences among digicert, SECTIONO and globalsign code signing certificates
迅為恩智浦iTOP-IMX6開發平臺
CMake教程系列-02-使用cmake代碼生成二進制
Ffmpeg source code
Unity TimeLine 数据绑定
HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化
Two methods of SSL certificate format conversion