博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Shell 字符串的截取
阅读量:4657 次
发布时间:2019-06-09

本文共 795 字,大约阅读时间需要 2 分钟。

    直接上代码了。

1 linux-56:/install # cat 3.sh  2 #!/bin/sh 3 STR=HelloWorld 4 echo 'STR == ' $STR 5  6 echo ${STR:5:5} # == echo ${STR:5}  #结果为World 7 echo ${STR:5} # Use : ${STR:begin:len} #结果为World 8  9 expr substr "$STR" 6 5 #结果为World10 11 echo $STR | awk '{print substr($STR,6,5)}' #结果为World12 13 echo $STR | cut -c6-10 #结果为World14 15 #expr $STR : '\(.\\).*'16 17 echo $STR | dd bs=5 count=1 2>/dev/null #结果为Hello, 但是不带换行(count=1指仅拷贝一个块;bs=512指块大小为512个字节。)18 19 echo ""20 echo ${STR##*Hello} #结果为World  #从左向右截取最后一个string后的字符串21 echo ${STR#*Hello} #结果为World #从左向右截取第一个string后的字符串22 23 echo ${STR%%World*} #结果为Hello #从右向左截取最后一个string后的字符串24 echo ${STR%World*} #结果为Hello #从右向左截取第一个string后的字符串25 26 #ls -al | cut -d "." -f2 #这里可以得到文件夹的后缀名

 

注:dd命令可以参考

 

转载于:https://www.cnblogs.com/AndyStudy/p/6064951.html

你可能感兴趣的文章
Elgg网站迁移指南
查看>>
Sublime Text 3 及Package Control 安装(附上一个3103可用的Key)
查看>>
基于uFUN开发板的心率计(一)DMA方式获取传感器数据
查看>>
【dp】船
查看>>
oracle, group by, having, where
查看>>
nodejs pm2使用
查看>>
CSS选择器总结
查看>>
mysql中sql语句
查看>>
sql语句的各种模糊查询语句
查看>>
C#操作OFFICE一(EXCEL)
查看>>
【js操作url参数】获取指定url参数值、取指定url参数并转为json对象
查看>>
移动端单屏解决方案
查看>>
web渗透测试基本步骤
查看>>
使用Struts2标签遍历集合
查看>>
angular.isUndefined()
查看>>
第一次软件工程作业(改进版)
查看>>
网络流24题-飞行员配对方案问题
查看>>
引入css的四种方式
查看>>
iOS开发UI篇—transframe属性(形变)
查看>>
3月7日 ArrayList集合
查看>>