sed的详细用法demo
来源:互联网 发布:isp图像处理编程 编辑:程序博客网 时间:2024/05/01 19:30
先创建一个文件test
内容为:
lijie1:one lijie2:two lijie3:threehehe1:one1 hehe2:two2 hehe3:three3
1.查找
[root@lijie hadoop]# sed -n /lijie/p testlijie1:one lijie2:two lijie3:three
2.对当前字段的删除
--匹配删除[root@lijie hadoop]# cat ./test | sed /lijie/dhehe1:one1 hehe2:two2 hehe3:three3--指定函数删除[root@lijie hadoop]# cat ./test | sed 2dlijie1:one lijie2:two lijie3:three--多行删除(1-4行)[root@lijie hadoop]# cat ./test | sed 1,4d--删除到最后[root@lijie hadoop]# cat ./test | sed "3,$"d
3.替换
--给替换第一个[root@lijie hadoop]# cat test | sed s/hehe/heihei/lijie1:one lijie2:two lijie3:threeheihei1:one1 hehe2:two2 hehe3:three3--替换所有[root@lijie hadoop]# cat test | sed s/hehe/heihei/glijie1:one lijie2:two lijie3:threeheihei1:one1 heihei2:two2 heihei3:three3
4.替换然后打印匹配行
[root@lijie hadoop]# cat test | sed -n /three3/s/hehe/heihei/gpheihei1:one1 heihei2:two2 heihei3:three3
5.复合条件-e(把lijie换成hadoop,把匹配three3的hehe换为heihei)
[root@lijie hadoop]# cat test | sed -n -e s/lijie/hadoop/gp -e /three3/s/hehe/heihei/gphadoop1:one hadoop2:two hadoop3:threeheihei1:one1 heihei2:two2 heihei3:three3
6.对文件进行修改
[root@lijie hadoop]# sed -i -n -e s/lijie/hadoop/gp -e /three3/s/hehe/heihei/gp test [root@lijie hadoop]# cat test hadoop1:one hadoop2:two hadoop3:threeheihei1:one1 heihei2:two2 heihei3:three3
7.将某个文件的文件替换到匹配的那一行后面(r和R不同)
--r[root@lijie hadoop]# sed /hadoop/'r test1' testhadoop1:one hadoop2:two hadoop3:threen1n2heihei1:one1 heihei2:two2 heihei3:three3--R[root@lijie hadoop]# sed /hadoop/'r test1' testhadoop1:one hadoop2:two hadoop3:threen1heihei1:one1 heihei2:two2 heihei3:three3hadoop4:one hadoop5:two hadoop6:threen2hadoop7:one hadoop8:two hadoop9:three
8.追加字符a为匹配行后,i为匹配行前
[root@lijie hadoop]# sed /hadoop/'a this is append str' testhadoop1:one hadoop2:two hadoop3:threethis is append strheihei1:one1 heihei2:two2 heihei3:three3[root@lijie hadoop]# sed /hadoop/'i this is append str' testthis is append strhadoop1:one hadoop2:two hadoop3:threeheihei1:one1 heihei2:two2 heihei3:three3
9.整行替换
[root@lijie hadoop]# sed /hadoop/'c new line' testnew lineheihei1:one1 heihei2:two2 heihei3:three3
1 0
- sed的详细用法demo
- awk的详细用法demo
- sed详细用法
- sed 详细用法
- 史上最详细sed用法
- sed的用法
- sed的用法
- sed参数的用法
- sed 的用法
- sed 命令的用法
- sed命令的用法
- 有关sed的用法
- sed的用法
- shell sed的用法
- Sed命令的用法
- Sed的基本用法
- SED 的精细用法
- sed的一些用法
- JAVA中==和equals的区别
- 笑死了,打错一个字,竟然...
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来. 提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headhaubo
- 内存映射+矩阵
- prolog学习_修道士野人问题
- sed的详细用法demo
- 2016年11月
- 利用命令来打开所有程序,这个装逼给满分!
- javaweb项目在linux系统中测试时的乱码问题解决
- View的事件分发机制
- Atitit 图像处理 灰度图片 灰度化的原理与实现
- Atitit Gaussian Blur 高斯模糊 的原理and实现and 用途
- 小波的秘密3_连续、离散小波变换定义
- 苏嵌2 16.10.31