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/^/# /
|
Script2 [perl] [ 1] s/^(?!#)/# /
| |
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/^/# /
| |
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/^/# /
| |