PDA

View Full Version : How to solve this problem with sed



flylehe
September 3rd, 2009, 08:32 PM
Hi,
I have many such parts in my file


main.o : main.cc defs.h \
src/misc.h


I want to specify some prefix right before the object files, i.e.


$(BIN_DIR)main.o : main.cc defs.h \
src/misc.h


How to do it by sed?

Thanks and regards!

stroyan
September 3rd, 2009, 08:56 PM
Assuming that the targets that you want to change all consist of alphanumeric characters and periods followed by an optional group of spaces and a colon, use-

sed -e 's/^[[:alnum:].]\+ *:/\$(BIN_DIR)&/' Makefile > Makefile.new
That will put the "$(BIN_DIR)" in front of every line that starts with that pattern.
You may need to tweek the pattern to match only the lines that you want.

ghostdog74
September 4th, 2009, 01:29 AM
awk -F":" '/\.o /{ $1="${BINIR}"$1}1' file