1、测试文件
root@PC1:/home/test# ls a.txt root@PC1:/home/test# cat a.txt >1 e r >2 s d >3 i j >4 z c >5 a t >6 e d >7 3 7 >8 z d >9 a c >10 t a >11 a c
2、删除匹配s及其后的2行
root@PC1:/home/test# ls a.txt root@PC1:/home/test# cat a.txt >1 e r >2 s d >3 i j >4 z c >5 a t >6 e d >7 3 7 >8 z d >9 a c >10 t a >11 a c root@PC1:/home/test# sed '/s/,+2d' a.txt ## 删除匹配s及其后的两行 >1 e r >5 a t >6 e d >7 3 7 >8 z d >9 a c >10 t a >11 a c
3、删除匹配e及其后的2行
root@PC1:/home/test# ls a.txt root@PC1:/home/test# cat a.txt >1 e r >2 s d >3 i j >4 z c >5 a t >6 e d >7 3 7 >8 z d >9 a c >10 t a >11 a c root@PC1:/home/test# sed '/e/, +2d' a.txt ## 删除匹配e及其后的2行 >4 z c >5 a t >9 a c >10 t a >11 a c