zoukankan      html  css  js  c++  java
  • sed删除指定行以及前n行

    有文本文件,内容如下,需要找出response不为on的设备ip

    root@dev[15:49:33]$ cat result.txt 
    index[8] ip[8.8.8.8] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100     2  100     2    0     0   1031      0 --:--:-- --:--:-- --:--:--  2000
    on]
    index[4] ip[8.8.8.9] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100     2  100     2    0     0    883      0 --:--:-- --:--:-- --:--:--  2000
    on]
    index[5] ip[1.1.1.1] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100    26  100    26    0     0  22127      0 --:--:-- --:--:-- --:--:-- 26000
    local cache is unavailable]
    index[3] ip[2.2.2.2] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100     2  100     2    0     0   1162      0 --:--:-- --:--:-- --:--:--  2000
    on]
    index[6] ip[3.3.3.3] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100    26  100    26    0     0  22127      0 --:--:-- --:--:-- --:--:-- 26000
    local cache is not found]
    root@dev[15:51:36]$ 
    

    删除指定行以及下面几行

    root@dev[15:53:42]$ sed '/unavailable/,+7 d' result.txt 
    index[8] ip[8.8.8.8] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100     2  100     2    0     0   1031      0 --:--:-- --:--:-- --:--:--  2000
    on]
    index[4] ip[8.8.8.9] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100     2  100     2    0     0    883      0 --:--:-- --:--:-- --:--:--  2000
    on]
    index[5] ip[1.1.1.1] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100    26  100    26    0     0  22127      0 --:--:-- --:--:-- --:--:-- 26000
    local cache is not found]
    root@dev[15:53:53]$

    删除指定行以及上面几行

    root@dev[15:53:53]$ tac result.txt |sed '/^on]/,+3 d' |tac
    index[5] ip[1.1.1.1] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100    26  100    26    0     0  22127      0 --:--:-- --:--:-- --:--:-- 26000
    local cache is unavailable]
    index[6] ip[3.3.3.3] send response[  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100    26  100    26    0     0  22127      0 --:--:-- --:--:-- --:--:-- 26000
    local cache is not found]
    root@dev[15:54:59]$ 
  • 相关阅读:
    1.1下载
    【翻译】培训提示:解决常见编码问题的简单技巧
    小猪的Git使用总结
    Singleton单例模式是最简单的设计模式,它的主要作用是保证在程序执行生命周期中,使用了单类模式的类仅仅能有一个实例对象存在。
    springweb flux 编程模型
    java aop做一个接口耗时的计算
    mysql保留两位小数
    在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现Web端直传,服务端签名直传并设置上传回调的实现流程
    Windows下编译使用Aliyun OSS PHP SDK
    windows下Gulp入门详细教程 &&gulp安装失败的原因(红色)
  • 原文地址:https://www.cnblogs.com/standby/p/14202024.html
Copyright © 2011-2022 走看看