Shell(Bash) - 文件名.字符串截取
2009-11-23 23:37
435 查看
对于常用的字符串截取方式:
1.在LINUX中截取字符串方法
${string:position}
在string中从位置$position开始提取子串.
如果$string为"*"或"@",那么将提取从位置$position开始的位置参数
${string:position:length}
在string中从位置$position开始提取$length长度的子串.
例子:
read word
cut=${A:3:8}
echo "$word $cut"
2.在UNIX中截取字符串的方法
通过管道输出,通过cut处理字符串:
例子:
read word
cut=`echo $word|cut -c4-8`
echo "$word $cut"
或者使用awk截取字符串
例子:
read word
cut=`echo $word|awk '{print substr{$1,2,6}'`
echo "$word $cut"
3.调用expr命令,expr支持substr函数
expr substr "abcdef" 2 2
expr match "$string" '$substring'
$substring是一个正则表达式
expr "$string" : '$substring'
$substring是一个正则表达式
1.在LINUX中截取字符串方法
${string:position}
在string中从位置$position开始提取子串.
如果$string为"*"或"@",那么将提取从位置$position开始的位置参数
${string:position:length}
在string中从位置$position开始提取$length长度的子串.
例子:
read word
cut=${A:3:8}
echo "$word $cut"
2.在UNIX中截取字符串的方法
通过管道输出,通过cut处理字符串:
例子:
read word
cut=`echo $word|cut -c4-8`
echo "$word $cut"
或者使用awk截取字符串
例子:
read word
cut=`echo $word|awk '{print substr{$1,2,6}'`
echo "$word $cut"
3.调用expr命令,expr支持substr函数
expr substr "abcdef" 2 2
expr match "$string" '$substring'
$substring是一个正则表达式
expr "$string" : '$substring'
$substring是一个正则表达式
相关文章推荐
- bash shell字符串的截取
- [Shell] 文件名截取的问题:bash .vs. csh
- [Linux]:Bash shell字符串截取及命令替换
- [Linux]:bash shell字符串的截取
- shell脚本的学习1-截取字符串
- [转]shell字符串截取
- shell与awk学习复习例子(循环与字符串截取判断)
- 【转】shell字符串的截取
- Shell(Bash)编程实例之获取某个文件夹下的所有文件名(含文件夹)
- shell截取字符串的方法
- shell字符串的截取的问题
- bat 根据文件名截取字符串,进行移动文件,复制文件
- shell截取字符串
- linux中shell截取字符串方法总结
- 【转】shell字符串的截取
- Shell字符串截取
- shell编程——文件名截取
- Bash Shell字符串操作小结
- shell字符串的截取
- Bash shell 连接字符串