linux shell 字符串截取总结
来源:互联网 发布:java 商城 小程序 编辑:程序博客网 时间:2024/04/28 21:19
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长度的字符串
- linux shell 字符串截取总结
- linux中shell截取字符串方法总结
- linux中shell截取字符串方法总结
- Linux shell截取字符串方法总结
- linux中shell截取字符串方法总结
- linux中shell截取字符串方法总结
- linux中shell截取字符串方法总结
- 【转】linux shell字符串截取方法总结
- linux中shell截取字符串方法总结
- linux中shell截取字符串方法总结
- linux中shell截取字符串方法总结
- linux中shell截取字符串方法总结
- linux中shell截取字符串方法总结
- linux shell截取字符串
- linux shell 字符串截取
- linux shell截取字符串
- linux shell截取字符串
- Linux shell字符串截取
- 外包如何逃离垃圾客户案例(转)
- 【转】U-BOOT源码分析及移植
- java 小数四舍五入 保留两位小数
- C#操作EXCEL 重要
- NAT穿透
- linux shell 字符串截取总结
- SSH server登录慢的解决办法
- HTML中meta的作用
- linux cat命令
- c#关于EXCEL导入数据库的做法
- windows 程序设计 奥运五环
- 给虚拟打印机添加A3纸支持
- 滚动条
- 工作之中,这点算什么