Description
A line is 'commented' if is begins with '#'. What we want is adding '# ' to uncommented lines.
Raw Input Desired Output
a
# b
c # d e
f # g
# a
# b
# 
# c
# d
# e
# 
# f
# g
Script and Comments
Script1 [sed]
[ 1] /^#/!s/^/# /
Comments
  1. Step [1] will apply s/// command on a line if it is NOT matched by ^#, i.e., does not begins with a '#'.
Script2 [perl]
[ 1] s/^(?!#)/# /
Comments
  1. You can use '-p' and '-e' options to run this perl script in one line: perl -pe 's/^(?!#)/# /' datafile
One More constraint
To comment out uncommented lines which are 50th up to 100th lines of a file, we can use the following script:
Script and Comments
Script1
[ 1] 50,100!b
[ 2] /^#/!s/^/# /
Comments
  1. If a line is not in the specified range, command 'b' will make sed branch to the end of script, print it out (actually, the contents of Pattern Space), then start a new cycle.
More constraint
How to comment out uncomment lines which are 50th up to 100th, 150th up to 200th lines of a file?
Script and Comments
Script1
[ 1] 50,100b br1
[ 2] 150,200!b
[ 3] :br1
[ 4] /^#/!s/^/# /
Comments
  1. Step [2] will be performed on every line that is not in the specified range.
  2. Each line in the specified ranges will make sed branch to Step [4] then [5].