To run an example question just
sed 's/^# //' file
thatโs enough, but if you need to delete a comment only on some lines containing a certain regular expression, you can use a conditional address :
sed '/regex/s/^# //' file
Thus, all lines containing regex will not be commented out (if the line starts with # )
... where regex can be [0-9]$ like:
sed '/[0-9]$/s/^# //' file
will delete # at the beginning of lines containing the number as the last character.
AND
sed '/12$/s/^# //' file
will delete # at the beginning of lines ending in 12 . Or
sed '/one two/s/^# //' file
will delete # at the beginning of lines containing one two .
F. Hauri
source share