当前位置:网站首页>Shell counts all strings before the last occurrence of a string
Shell counts all strings before the last occurrence of a string
2022-06-30 02:58:00 【Yabingshi】
demand :
I want to count some ip Network segment .
Example :
There's a server ip yes 192.168.144.249, I want to count 192.168.144 This segment .
Method 1 :
strToCheck='192.168.144.251'
letpos=`echo "$strToCheck" | cut -d '.' -f 1,2,3`
echo $letpos
The result is 192.168.144
Method 2 is more complicated :
# Count the last one first . In which position
strToCheck='192.168.144.249'
charToSearch='.'
letpos=`echo "$strToCheck" | awk -F ''$charToSearch'' '{printf "%d", length($0)-length($NF)}'`
# Then count the string in front of the position
echo ${strToCheck:0:$letpos}
result 192.168.144.
-- This article is from :Shell Script implementation finds the last position of a character in the string / Sheng Rong Zhang
边栏推荐
- CMake教程系列-02-使用cmake代碼生成二進制
- 【微信小程序】条件渲染 列表渲染 原来这样用?
- What is the metauniverse: where are we, where are we going
- Distributed file system fastdfs
- Three solutions to forced hibernation of corporate computers
- Unity TimeLine 数据绑定
- shell统计某个字符串最后一次出现的位置之前的所有字符串
- How to set password complexity and timeout exit function in Oracle
- Which is a good foreign exchange trading platform? Is it safe to have regulated funds?
- Distributed file storage system fastdfs hands on how to do it
猜你喜欢

Mysql提取表字段中的字符串

福利抽奖 | 开源企业级监控Zabbix6.0都有哪些亮点

Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)

Raki's notes on reading paper: Leveraging type descriptions for zero shot named entity recognition and classification

自定义JvxeTable的按钮及备注下$set的用法

GTK interface programming (I): Environment Construction

Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery

Distributed file storage system fastdfs hands on how to do it

Implementation of Sanzi chess with C language

Unity TimeLine 数据绑定
随机推荐
Some configuration details about servlet initial development
Global and Chinese market of ERP software for garment and textile industries 2022-2028: Research Report on technology, participants, trends, market size and share
Cmake tutorial series -05- options and variables
O & M (20) make and start USB flash disk and install win10
可视化HTA窗体设计器-HtaMaker 界面介绍及使用方法,下载 | HTA VBS可视化脚本编写
2. < tag dynamic programming and 0-1 knapsack problem > lt.416 Split equal sum subset + lt.1049 Weight of the last stone II
Unity3D UGUI强制刷新Layout(布局)组件
What is the metauniverse: where are we, where are we going
Time complexity analysis
公司电脑强制休眠的3种解决方案
Implementation of Sanzi chess with C language
Global and Chinese markets of liquid optical waveguides 2022-2028: Research Report on technology, participants, trends, market size and share
Heavy attack -- ue5's open source digital twin solution
Recursion frog jumping steps problem
GTK interface programming (I): Environment Construction
快速排序、聚簇索引、寻找数据中第k大的值
CMake教程系列-03-依赖管理
2022 tool fitter (Advanced) and tool fitter (Advanced) certificate examination
Visual HTA form designer htamaker interface introduction and usage, Download | HTA VBS visual script writing
Quick sort, cluster index, find the k-largest value in the data