如何使用bash注释掉任意范围的行?

时间:2019-10-09 02:00:51

标签: bash sed

说我有以下file.txt

some line 

{
  hey it's me, another line
}

# START FOO
These lines
need to be commented
out
# END FOO

Some other line

如何注释掉# START FOO中标记# END FOObash之间的所有行?一口气可以做到吗?

1 个答案:

答案 0 :(得分:4)

尝试一下:

sed '/START FOO/,/END FOO/s/^/#/' file.txt