首页 > 系统相关 >linux 中sed命令删除匹配字符之后、之前的若干行

linux 中sed命令删除匹配字符之后、之前的若干行

时间:2022-12-08 20:12:25浏览次数:53  
标签:字符 10 PC1 sed linux test txt root

 

001、 删除匹配字符之后的若干行

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt             ## 测试数据
1
2
3
4
5
6
7
8
9
10
[root@PC1 test]# sed '/5/,+1{/5/b;d}' a.txt       ## 删除匹配5之后的1行
1
2
3
4
5
7
8
9
10
[root@PC1 test]# sed '/5/,+3{/5/b;d}' a.txt       ## 删除匹配5之后的3行
1
2
3
4
5
9
10

 

 

002、删除匹配字符之前的若干行

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
1
2
3
4
5
6
7
8
9
10
[root@PC1 test]# tac a.txt | sed '/5/,+1{/5/b;d}' | tac        ## 删除匹配5之前的1行
1
2
3
5
6
7
8
9
10
[root@PC1 test]# tac a.txt | sed '/5/,+3{/5/b;d}' | tac       ## 删除匹配5之前的3行
1
5
6
7
8
9
10

 

标签:字符,10,PC1,sed,linux,test,txt,root
From: https://www.cnblogs.com/liujiaxin2018/p/16967150.html

相关文章

  • 字符串处理常用技术
    CString中空格的去除方式一:cstring.replace('',NULL);//截取去除空格 此法同样可以去掉其它不想要的符号:cstring.replace('-',NULL);cs......
  • 编译arm_qt-4.5_build出错与Linux vi的使用
     ​​Linux(vi基本用法)​​ 在Linux下,可以键入vimtutor命令,有一个包含实操的vim教程。1.VI的三种命令模式 1)Command(命令)模式,用于输入命令; 2)......
  • 在win7下与linux虚拟机Ubuntu建立共享文件夹
      使用vmware(vmwareworkstation9.0.2)下sharedfolders功能实现vmware中文件传输,可参考vmware帮助中settingupsharedfolders。 1.安装vmtoolsforlinux: 选......
  • ubuntu 10.04下编译linux内核make menuconfig报 'make menuconfig' requires the ncur
    在ubuntu11.10下编译linux内核出现如下错误:​​echo@echo-desktop:~/freescale/kernel/src/linux-2.6.35-sitek20091229$​​ makemenuconfig ***Unabletofindth......
  • 非入侵式Linux 性能监控面板 NetData安装部署流程。
    构建最佳的实时健康监控和性能故障排除解决方案:Netdata是一款Linux性能实时监测工具.。以web的可视化方式展示系统及应用程序的实时运行状态(包括cpu、内存、硬盘输入/输......
  • 在linux环境中安装node,npm,express
    linux安装node连接运程命令:进入usr/local文件夹cd/usr/local1.下载wgethttps://nodejs.org/dist/v14.17.6/node-v14.17.6-linux-x64.tar.xz2.解压tarxvf......
  • 443.string-compression 压缩字符串
    问题描述443.压缩字符串解题思路双指针、滑动窗口,注意for循环中不需要fast++。代码classSolution{public:intcompress(vector<char>&chars){vect......
  • java基础知识-字符编码
    这块比较乱待整理。。。​​http://www.regexlab.com/zh/encoding.htm​​字符编码字符集。把这些字符集按照不用规则进行编码就形成了不同的字符编码。为什么我们在上网或......
  • linux 内核升级
    CentOS7升级内核到4.4以上版本时重启无法进入系统https://www.cnblogs.com/xzy186/p/15135919.htmllinuxrecovery升级内核,记一次CentOS7.6内核升级(5.9.6)及故障......
  • linux系统怎么安装宝塔面板
    linux系统怎么安装宝塔面板​怎么安装宝塔面板?这个其实很简单接下来跟着我操作:以linuxcentos7.6举例​Centos安装脚本:​yuminstall-ywget&&wget-Oinstall.shhttp......