当前位置:网站首页>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
边栏推荐
- O & M (20) make and start USB flash disk and install win10
- Study diary: February 15, 2022
- uniapp 地址转换经纬度
- SQLite use
- Raki's notes on reading paper: neighborhood matching network for entity alignment
- How to switch ipykernel to a different CONDA virtual environment in jupyterlab?
- Network neuroscience -- a review of network Neuroscience
- Raki's notes on reading paper: Leveraging type descriptions for zero shot named entity recognition and classification
- Note the use of export/import and class inheritance in ES6
- Multi card server usage
猜你喜欢

Distributed file system fastdfs

Wechat applet page Jump and parameter transfer

Distributed file storage system fastdfs hands on how to do it

Cmake tutorial series -02- generating binaries using cmake code

Intel-Hex , Motorola S-Record 格式详细解析

CMake教程系列-02-使用cmake代码生成二进制

Ffmpeg source code

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

LeetCode 3. 无重复字符的最长子串

Idea remote debugging remote JVM debug
随机推荐
Cmake tutorial series-03-dependency management
怎样的外汇交易平台是有监管的,是安全的?
List of development tools
Some technology sharing
Recursion frog jumping steps problem
Cmake tutorial series -04- compiling related functions
Global and Chinese market of mobile commerce solutions 2022-2028: Research Report on technology, participants, trends, market size and share
Welfare lottery | what are the highlights of open source enterprise monitoring zabbix6.0
迅為恩智浦iTOP-IMX6開發平臺
Functions in C language
Formal and actual parameters, value passing and address passing
Idea remote debugging remote JVM debug
How to set password complexity and timeout exit function in Oracle
【实战技能】如何撰写敏捷开发文档
怎么使用Vant实现数据分页和下拉加载
Redis+AOP怎么自定义注解实现限流
Global and Chinese markets of liquid optical waveguides 2022-2028: Research Report on technology, participants, trends, market size and share
Summary of knowledge points about eigenvalues and eigenvectors of matrices in Chapter 5 of Linear Algebra (Jeff's self perception)
Three solutions to forced hibernation of corporate computers
What is the difference between a layer 3 switch and a layer 2 switch