Search code examples
regexbashsedcomments

I need to use sed to comment out two lines in a text file


I am running a custom kernel build and have created a custom config file in a bash script, now I need to comment out two lines in Kbuild in order to prevent the bc compiler from running. The lines are...

$(obj)/$(timeconst-file): kernel/time/timeconst.bc FORCE
    $(call filechk,gentimeconst)

Using Expresso, I have a regex that matches the first line...

^\$\(obj\)\/\$\(timeconst-file\): kernel\/time\/timeconst\.bc FORCE

Regex Match

But can't get sed to actually insert a # in front of the line.

Any help would be much appreciated.


Solution

  • You can use following sed for replacement:

    sed  's,^\($(obj)/$(timeconst-file): kernel/time/timeconst.bc FORCE\),#\1,'
    

    You don't need to escape ( ) or $, as in sed without -r it is treated as literal, for grouping \( \) is used.