Currently i have files, which contain sections like thiscode statement1code statement2# BEGIN SOMENAMEsome codesome other code# END SOMENAMEcode statement n +1code statement n +1What i want to do is to comment out what is between # BEGIN SOMENAME and # END, so that in the end it looks like thiscode statement1code statement2# BEGIN SOMENAME# some code# some other code# END SOMENAMEcode statement n +1code statement n +1Can i achieve this with awk or sed?   and can i reverse it easily?, so just an operation, which comments in again?  What i want to avoid to make mistakes, so if the lines are already commented outit should be left alone. Also in comment in it should not try to do something if the lines between end and begin do not start with with a #.Tried that now for several hours, no success.Found a possible solutin:awk 'BEGIN                      { i=0; line_with_no_comment_found=0 }/^# END/                  { m=0;                             if ( line_with_no_comment_found == 1 )                               { for (var in a) print # a[var] }                             else                               { for (var in a) print a[var] }                             delete a;                             i=0;                             line_with_no_comment_found=0;                           }/^# /                      { if (m==0) { print } else { a[i++]=$0; } }!/^# /                     { if (m==0) { print } else { a[i++]=$0; line_with_no_comment_found=1} }/^# BEGIN ([a-zA-Z_])([1-9][0-9]*)*/ {m=1;}END { }'<<EOF
how can i comment out/in a section in source code with sed or awk
sed;awk