001、
(base) [email protected]:/home/test2# ls a.txt (base) [email protected]:/home/test2# cat a.txt ## 测试数据 01 02 AAA 03 04 05 BBB 06 07 08 CCC 09 10 (base) [email protected]:/home/test2# sed '/AAA/,/BBB/d' a.txt ## 删除匹配AAA和BBB之间的数据 01 02 06 07 08 CCC 09 10
002、
(base) [email protected]:/home/test2# cat a.txt 01 02 AAA 03 04 05 BBB 06 07 08 CCC 09 10 (base) [email protected]:/home/test2# sed '/AAA/,/BBB/{/AAA/b; d}' a.txt ## 删除匹配AAA,BBB之间的数据,同时保护AAA 01 02 AAA 06 07 08 CCC 09 10
003、
(base) [email protected]:/home/test2# cat a.txt 01 02 AAA 03 04 05 BBB 06 07 08 CCC 09 10 (base) [email protected]:/home/test2# sed '/AAA/,/BBB/{/BBB/b; d}' a.txt ## 保留BBB 01 02 BBB 06 07 08 CCC 09 10 (base) [email protected]:/home/test2# sed '/AAA/,/BBB/{/AAA/b; /BBB/b; d}' a.txt ## 同时保留AAA和BBB 01 02 AAA BBB 06 07 08 CCC 09 10