• 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]$ 
  • 相关阅读:
    CodeForces.1174D.EhabandtheExpectedXORProblem(构造前缀异或和数组)
    HDU-6187.DestroyWalls(最大生成树)
    HDU.6186.CSCource.(前缀和数组和后缀和数组)
    <每日一题>Day 9:POJ-3281.Dining(拆点 + 多源多汇+ 网络流 )
    <每日一题> Day8:CodeForces-996A.Hit the Lottery(贪心)
    最小割 + 网络流变体
    <每日一题> Day7:CodeForces-1166C.A Tale of Two Lands (二分 + 排序)
    <每日一题> Day6:HDU递推专题完结
    <每日一题> Day5:简单递推两题
    POJ-3122.Pie(二分法最大化平均值)
  • 原文地址:https://www.cnblogs.com/standby/p/14202024.html
Copyright © 2020-2023  润新知