001、
root@DESKTOP-1N42TVH:/home/test2# ls a.txt root@DESKTOP-1N42TVH:/home/test2# cat a.txt 1 01 2 02 3 AAA 4 03 5 04 6 03 7 BBB 8 06 9 07 10 BBB 11 08 12 CCC 13 09 14 AAA 15 10 16 BBB 17 33 root@DESKTOP-1N42TVH:/home/test2# sed '/AAA/d' a.txt ## 删除匹配AAA的行 1 01 2 02 4 03 5 04 6 03 7 BBB 8 06 9 07 10 BBB 11 08 12 CCC 13 09 15 10 16 BBB 17 33
002、删除匹配AAA的行及其后的2行
root@DESKTOP-1N42TVH:/home/test2# ls a.txt root@DESKTOP-1N42TVH:/home/test2# cat a.txt 1 01 2 02 3 AAA 4 03 5 04 6 03 7 BBB 8 06 9 07 10 BBB 11 08 12 CCC 13 09 14 AAA 15 10 16 BBB 17 33 root@DESKTOP-1N42TVH:/home/test2# sed '/AAA/,+2d' a.txt ## 删除匹配AAA的行及其后的2行 1 01 2 02 6 03 7 BBB 8 06 9 07 10 BBB 11 08 12 CCC 13 09 17 33
003、
root@DESKTOP-1N42TVH:/home/test2# ls a.txt root@DESKTOP-1N42TVH:/home/test2# cat a.txt 1 01 2 02 3 AAA 4 03 5 04 6 03 7 BBB 8 06 9 07 10 BBB 11 08 12 CCC 13 09 14 AAA 15 10 16 BBB 17 33 root@DESKTOP-1N42TVH:/home/test2# sed '/AAA/,/BBB/d' a.txt ## 删除AAA和BBB之间的行 1 01 2 02 8 06 9 07 10 BBB 11 08 12 CCC 13 09 17 33
原创文章,作者:745907710,如若转载,请注明出处:https://blog.ytso.com/275067.html