Shell 字符串常见操作
参考文章:http://blog.csdn.net/chen_jp/article/details/8922582
一 字符替换
origin=原字符串 str=替换后的字符串
替换命令:
str=${origin//目标字符/替换后的字符}
例如:
str=${origin//:/_}
代码示例:
origin='mark:x:0:0:this is a test user:/var/mark:nologin'
str=${origin//:/_}
echo ${origin}
echo ${str}
输出:
mark:x:::this is a test user:/var/mark:nologin
mark_x_0_0_this is a test user_/var/mark_nologin
二 字符串分割
origin='mark:x:0:0:this is a test user:/var/mark:nologin'
i=
while((==))
do
split=`echo $origin|cut -d ":" -f$i`
if [ "$split" != "" ]
then
((i++))
echo $split
else
break
fi
done
输出:
mark
x this is a test user
/var/mark
nologin
Shell 字符串常见操作的更多相关文章
- python字符串常见操作
字符串常见操作 如有字符串mystr = 'hello world itcast and itcastcpp',以下是常见的操作 <1>find 检测 str 是否包含在 mystr中,如 ...
- python基础学习-字符串常见操作
字符串常见操作 索引 s = "abcdefg" # 字符串数据,切片后取出的数据都是字符串类型 # 从左至右取值:从0开始 # 从右向左取值:从-1开始 print(" ...
- linux shell 字符串常用操作
1.shell内置的字符串操作 表达式 含义 ${#string} $string的长度 ${string:position} string中,从位置$position开始提取字符串 ${string ...
- Python中字符串常见操作
(1)find 查找 格式:mystr.find(str, start, end) 例如: mystr.find(str, start=0, end=len(mystr)) 作用:检测str是否包含在 ...
- python中字符串常见操作(二)
# 可迭代对象有:字典,列表,元组,字符串,集合 str1 = '192.168.1.1' str2 = 'as df gh jk' str3 = '小李子' str4 = ['aa','bb','c ...
- JAVA中字符串常见操作
String str1="hello,world";String str2="Hello,World"; 1.字符串的比较:例,System.out.print ...
- Go 语言字符串常见操作
@ 目录 1. 字节数组 2. 头尾处理 3. 位置索引 4. 替换 5. 统计次数 6. 重复 7. 大小写 8. 去除字符 9. 字符串切片处理 10. 数值处理 1. 字节数组 字节与字符的区别 ...
- C#字符串常见操作总结
string类常用的方法和总结小记
- Java Script中常见操作
字符串常见操作:obj.length 长度obj.trim() 移除空白obj.trimLeft()obj.trimRight)obj.charAt(n) 返回字符串中的第n个字符obj.concat ...
随机推荐
- 计算1至n中数字X出现的次数
描述 计算 1 至 n 中数字 X 出现的次数,其中 $n \ge 1,X \in [0,9]$. 解题思路 这是一道比较简单的题目,举个例子先:假设 $n=11, X=1$,那么就是求 1, 2, ...
- 游戏 slider
using UnityEngine; using System.Collections; public class La : MonoBehaviour { float verticalValue=0 ...
- 【POJ】1269 Intersecting Lines(计算几何基础)
http://poj.org/problem?id=1269 我会说这种水题我手推公式+码代码用了1.5h? 还好新的一年里1A了---- #include <cstdio> #inclu ...
- 【BZOJ】1601: [Usaco2008 Oct]灌水(kruskal)
http://www.lydsy.com/JudgeOnline/problem.php?id=1601 很水的题,但是一开始我看成最短路了T_T 果断错. 我们想,要求连通,对,连通!连通的价值最小 ...
- CentoS 下报的 Requires: perl(:MODULE_COMPAT_5.8.8)
yum error requires: libtcmalloc.so.4 rpm -Uvh http://ceph.com/rpm-cuttlefish/el6/x86_64/ceph-release ...
- Javascript Math ceil()、floor()、round()三个函数的区别
Round是四舍五入的...Ceiling是向上取整..float是向下取整. ceil():将小数部分一律向整数部分进位. 如: Math.ceil(12.2)//返回13 Math.ceil(12 ...
- opengl绘制正弦曲线
利用opengl绘制正弦曲线 ,见代码: #include <windows.h> //#include <GLUT/glut.h> #include <GL/glut. ...
- Linux Path文件夹内容
- 对于默认 Windows NT 安装的 SID 值
https://support.microsoft.com/en-us/kb/163846/zh-cn
- dig理解dns主备 - 阿权的书房
dns的解析一般都授权两个以上,防止单点故障. 比如阿权的书房的域名 www.aslibra.com,授权两台ns.aslibra.com 和 ns2.aslibra.com,如果单点故障会怎么样呢? ...