Reputation: 301
I have a file that has lines of code that are commented out and can be uncommented to become useful. Example:
#debug=true;
Is there a sed command that would search the file for "bug=tr" or "debug" and remove the first character (#)? So it would become active as:
debug=true;
Thank you in advance for looking at this for me!
Upvotes: 3
Views: 6113
Reputation:
Here is my version:
$ cat << EOF | sed -r 's/(#\s*)((de)?bug\s*\=\s*[tT]r(ue)?)/\2/'
> #debug=true
> # debug = true
> # bug = tr
> # debu = tue
> # buggy = tree
> EOF
debug=true
debug = true
bug = tr
# debu = tue
# buggy = tree
Upvotes: 0
Reputation: 241848
Yes, use the so called "address":
sed -e '/bug=tr/ s/^#//'
# if this ^^^^^^^
# is true, run this ^^^^^
Upvotes: 1
Reputation: 174706
You could use the below,
sed '/bug=tr\|debug/s/^#//' file
This would search for the line which has the string bug=tr
or debug
. If it finds any then it would do replace the #
symbol at the start with an empty string.
Example:
$ echo '#debug=true;' | sed '/bug=tr\|debug/s/^#//'
debug=true;
$ echo '#bug=true;' | sed '/bug=tr\|debug/s/^#//'
bug=true;
Upvotes: 2