Using sed in a Makefile
makefile, sed, unix
Solution
You should have tested the `sed` command on the command line before incorporating it into a makefile. As written it removes the lines you want it to remove-- and then directs the results to stdout. To modify the files in place you should use `-i`:
sed -i -e '/#--Begin/,/#--End/d' Docs/$@/conf.py
There may well be other problems. You haven't shown us the real makefile (`.PHONY $(SUBDIRS)` is not legal, so you're not pasting part a working makefile), but it's possible that the rule isn't even executing the way you think it should. Try this:
$(SUBDIRS):
@echo attempting to act on $@
@ls Docs/$@/conf.py
Get this to work perfectly before attempting to introduce the `sed` command.
Problem
I'm trying to make it so that a block of text of a file (`conf.py`) in each subdirectory (stored in the variable `SUBDIRS`) is deleted. This block of text is lies within the tags `#--Begin` and `#--End`. See code sample below. For the sake of being neat and not having to make an extra shell script to run from within the makefile, I'd like to use a sed command from within the makefile, but am having trouble doing so. I cannot find the solution to this on any other forum post, so any help would be gratefully received. ``` .PHONY $(SUBDIRS) SUBDIRS = (list of all subdirectories that contain a relevant conf.py) $(SUBDIRS): sed '/#--Begin/,/#--End/d' Docs/$@/conf.py ``` Nothing happens as a result of this command. Thanks!