linux shell 字符串截取总结
linux中对字符串的处理:
1.字符串分割例如 AAAAA-BBBBBB 按-分割去前后两部分
cut :
[rich@localhost ~]$ str=AAAAA-BBBBBB
[rich@localhost ~]$ echo $str | cut -d "-" -f 1
AAAAA
[rich@localhost ~]$ echo $str | cut -d "-" -f 2
BBBBBB
解释:A | B 将A命令的输出 作为B命令的输入
cut
-d :分隔符
-f : field 分割后的数组索引 只不过是从1开始
如果不存在分割符则返回全部:
[rich@localhost ~]$ echo $str | cut -d "c" -f 1
AAAAA-BBBBBB
expr && cut:
取“-”的索引
[rich@localhost ~]$ index=`expr index "${str}" "-"`
[rich@localhost ~]$ echo $str | cut -c`expr "${index}" + 1`-
BBBBBB
[rich@localhost ~]$ echo $str | cut -c1-`expr ${index} - 1`
AAAAA
cut
-c 截取字符串 索引从1开始
-cA- A到末尾
-cA A位置
-c A-B 索引A-B
-c-A 截取前A个字符
substr:
[rich@localhost ~]$ index=`expr ${index} - 1`
[rich@localhost ~]$ echo `expr substr "${str}" 1 ${index}`
AAAAA
substr str A B
从索引A开始截取B长度的字符串
相关文档:
一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......
linux网络编程
1. 基本概念
说到网络编程,不得不先提到OSI参考模型,其七层模型从下到上分别为
1.物理层(Physical Layer,PH)
2.数据链路层(Data Link Layer,DL)
3.网络层(Network Layer,N)
4.运输层(Transport Layer,T)
5.会话层(Session Layer,S)
......
0 引言
微处理器的产生为价格低廉、结构小巧的CPU和外设的连
接提供了稳定可靠的硬件架构,这样,限制嵌入式系统发展的瓶颈就突出表现在了软件方面。尽管从八十年代末开始,已经陆续出现了一些嵌入式操作系统(比较著
名的有Vxwork、pSOS、Neculeus和Windows
CE)。但这些专用操作系统都是商 ......