linux系统删除指定的⾏(sed命令)1、使⽤vim创建测试数据 a.txt
[root@linuxprobe test]#
1 w e t
2 s f h
3 z c g
4 e a g
5 a f w
6 k h d
7 w f r
2、删除指定的⾏
[root@linuxprobe test]# sed '3d' a.txt ##删除第三⾏
1 w e t
2 s f h
4 e a g
5 a f w
6 k h d
7 w f r
[root@linuxprobe test]# sed '1,3d' a.txt ## 删除1到3⾏
4 e a g
5 a f w
6 k h d
7 w f r
[root@linuxprobe test]# sed '1d;3d' a.txt ## 删除第⼀⾏和第三⾏
2 s f h
4 e a g
5 a f w
6 k h d
7 w f r
[root@linuxprobe test]# sed '/s/d' a.txt ##删除匹配s的⾏
1 w e t
3 z c g
4 e a g
5 a f w
6 k h d
7 w f r
[root@linuxprobe test]# sed '/w/d' a.txt ##删除匹配w的⾏
2 s f h
3 z c g
4 e a g
6 k h d
[root@linuxprobe test]# sed '/^5/d' a.txt ## 删除以5开头的⾏
1 w e t
2 s f h
3 z c g
4 e a g
6 k h d
7 w f r
[root@linuxprobe test]# sed '/^[35]/d' a.txt ## 删除以3或者5开头的⾏
1 w e t
2 s f h
4 e a g
6 k h d
7 w f r
[root@linuxprobe test]# sed '/h$/d' a.txt ## 删除以h结尾的⾏
1 w e t
3 z c g
4 e a g
5 a f wlinux系统vim编辑器
[root@linuxprobe test]# sed '/[hw]$/d' a.txt ## 删除以h或者w结尾的⾏
1 w e t
3 z c g
4 e a g
6 k h d
7 w f r
[root@linuxprobe test]#   ##使⽤vim编辑器重新编辑测试数据
1 w e t
2 s f 4
3 z c g
4 e a g
w a f w
6 k h d
t w f 2
[root@linuxprobe test]# sed '/^[0-9]/d' a.txt  ## 删除所有以数字开头的⾏
w a f w
t w f 2
[root@linuxprobe test]# sed '/^[a-zA-Z]/d' a.txt ## 删除所有以字母开头的⾏
1 w e t
2 s f 4
3 z c g
4 e a g
6 k h d
[root@linuxprobe test]# sed '/[0-9]$/d' a.txt ##删除所有以数字结尾的⾏
1 w e t
3 z c g
4 e a g
w a f w
6 k h d
[root@linuxprobe test]# sed '/[a-zA-Z]$/d' a.txt ##删除所有以字母结尾的⾏
2 s f 4
t w f 2
[root@linuxprobe test]# ## 使⽤vim 编辑器重新编辑测试数据
6 w e g
t s f g
2 z c g
2 e a t
y a f w
6 k h w
t w f 2
[root@linuxprobe test]# sed '/^2.*g$/d' a.txt  ## 删除以2开头,同时以g结尾的⾏6 w e g
t s f g
2 e a t
y a f w
6 k h w
t w f 2
[root@linuxprobe test]# ## 测试数据
6 w e g
t s f g
2 z c g
2 e a t
y a f w
6 k h w
t w f 2
[root@linuxprobe test]# sed '/e/,+1d' a.txt ## 删除包含e及其后1⾏
2 z c g
6 k h w
t w f 2
[root@linuxprobe test]# sed '/z/,+2d' a.txt ## 删除包含z及其后2⾏
6 w e g
t s f g

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。