-2

Say I have the following file.txt

some line 

{
  hey it's me, another line
}

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

Some other line

How could I comment out all lines between the markers # START FOO and # END FOO in bash? Is it possible to do it in a one-liner?

user2490003
  • 10,706
  • 17
  • 79
  • 155
  • see https://stackoverflow.com/questions/38972736/how-to-print-lines-between-two-patterns-inclusive-or-exclusive-in-sed-awk-or ... it should get you started.. – Sundeep Oct 09 '19 at 02:33
  • 2
    Since you have been around here for a long time, you should at least show what you have tried. – Jotne Oct 09 '19 at 04:55

1 Answers1

4

Try this:

sed '/START FOO/,/END FOO/s/^/#/' file.txt
Šerg
  • 793
  • 5
  • 18