Chinaunix首页 | 论坛 | 博客
  • 博客访问: 29944
  • 博文数量: 31
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 330
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-12 10:38
文章分类

全部博文(31)

文章存档

2015年(31)

我的朋友

分类: LINUX

2015-01-24 15:07:58

grep 行截取
cut, awk 列截取
sed  流编辑器

-n  把只经过sed处理的输出到屏幕
-i  修改结果输出到文件
-e 多条sed命令

a \:  追加
c \:  替换
i \:  插入
d:  删除
p:  打印
s:  字串替换 ,   s/旧字串/新字串/g

输出第二行
root@csc:/tmp/testdir# sed -n '2p' stu.txt
4444    5555    6666

删除第二行到第四行
root@csc:/tmp/testdir# sed '2,4d' stu.txt
1111    22222    3333

第二行后添加字串
root@csc:/tmp/testdir# sed '2a hello' stu.txt
1111    22222    3333
4444    5555    6666
hello

第二行前插入字串
root@csc:/tmp/testdir# sed '2i hello' stu.txt
1111    22222    3333
hello
4444    5555    6666

第二行替换
root@csc:/tmp/testdir# sed '2c hello' stu.txt
1111    22222    3333
hello

字串替换
root@csc:/tmp/testdir# sed '2s/444/9999/g' stu.txt
1111    22222    3333
99994    5555    6666

加-i, 写入文件。
root@csc:/tmp/testdir# sed -i '2s/444/9999/g' stu.txt

-e 多条件执行,替换为空,不是空格。
root@csc:/tmp/testdir# sed -e '2s/999//g;2s/9//g' stu.txt
1111    22222    3333
4    5555    6666







阅读(122) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~