1、测试数据
[root@rhel7pc1 test]# ls a.txt [root@rhel7pc1 test]# cat a.txt ## 测试数据 1 k d f 2 x c g 3 z c b 4 e w e 5 z c f 6 e d g
2、删除匹配行及其下一行
[root@rhel7pc1 test]# ls a.txt [root@rhel7pc1 test]# cat a.txt 1 k d f 2 x c g 3 z c b 4 e w e 5 z c f 6 e d g [root@rhel7pc1 test]# sed '/x/{N; d}' a.txt ## 删除匹配x的行及其下一行。 1 k d f 4 e w e 5 z c f 6 e d g
3、删除匹配行的下一行
[root@rhel7pc1 test]# ls a.txt [root@rhel7pc1 test]# cat a.txt 1 k d f 2 x c g 3 z c b 4 e w e 5 z c f 6 e d g [root@rhel7pc1 test]# sed '/x/ {n; d}' a.txt ## 删除匹配x行的下一行 1 k d f 2 x c g 4 e w e 5 z c f 6 e d g