删除:
[root@mhc regular]# sed '2,5d' num.txt
1
6
7
8
[root@mhc regular]# sed '5d' num.txt
1
2
3
4
6
7
8
[root@mhc regular]# sed '5,$d' num.txt
1
2
3
4
新增:
[root@mhc regular]# sed '2a hahaha' num.txt
1
2
hahaha
3
4
5
6
7
8
[root@mhc regular]# sed '2i hahaha' num.txt
1
hahaha
2
3
4
5
6
7
8
[root@mhc regular]#
[root@mhc regular]# sed '$a hahaha' num.txt
1
2
3
4
5
6
7
8
hahaha
[root@mhc regular]# sed '$i hahaha' num.txt
1
2
3
4
5
6
7
hahaha
8
[root@mhc regular]# sed '2a hahaha
> lala' num.txt
1
2
hahaha
lala
3
4
5
6
7
8
[root@mhc regular]# sed '2a hahaha
lalala' num.txt
1
2
hahaha
lalala
3
4
5
6
7
8
整行替换
[root@mhc regular]# sed '2,5c hahah' num.txt
1
hahah
6
7
8
打印
[root@mhc regular]# sed -n '5,7p' num.txt
5
6
7
[root@mhc regular]# sed -n '1,$p' num.txt
1
2
3
4
5
6
7
8
[root@mhc regular]# nl num.txt |sed -n '5,7p'
5 5
6 6
7 7
替换
[root@mhc regular]# sed 's/1/haha/g' num.txt
haha
2
3
4
5
6
7
8
[root@mhc regular]# sed 's/[1-9]/haha/g' num.txt
haha
haha
haha
haha
haha
haha
haha
haha