linux系统删除特定的行(sed命令)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux系统删除特定的行(sed命令),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2100字,纯文字阅读大概需要4分钟。
内容图文
![linux系统删除特定的行(sed命令)](/upload/InfoBanner/zyjiaocheng/936/688d254865b3473dbfb7fcf3bc834890.jpg)
1、使用vim创建测试数据 a.txt
[root@linuxprobe test]# cat a.txt 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 w 6 k h d 7 w f r [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]# cat a.txt ##使用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]# cat a.txt ## 使用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]# cat a.txt ## 测试数据
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 6 k h w t w f 2
内容总结
以上是互联网集市为您收集整理的linux系统删除特定的行(sed命令)全部内容,希望文章能够帮你解决linux系统删除特定的行(sed命令)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。