Thomas Ayoub
Thomas Ayoub

Reputation: 29431

Understand sed usage

I use sed to automaticaly update the version in my doxyfile using this :

sed -i -e "s/PROJECT_NUMBER.([ ]{2,}=.*)/PROJECT_NUMBER  = $$VERSION/g" ".doxygen"

with $$VERSION = 1.1.0 (for example)

and as a source :

PROJECT_NUMBER         = 1.0.10

But it generate an copy version of my .doxygen named .doxygen-e and don't change the line. I've tested my regex here.

I don't understand what's wrong given the fact that it works with my plist file using this :

sed -i -e "s/@VERSION@/$$VERSION/g" "./$${TARGET}.app/Contents/Info.plist"

Upvotes: 0

Views: 73

Answers (1)

devnull
devnull

Reputation: 123518

There are a couple of problems here:

You need to refer to a shell variable $FOO as $$FOO in a Makefile. If you are attempting to do it in bash or any other shell, saying:

$$FOO

would result in the numeric PID of the current process concatenated with FOO, e.g. if the PID of the current process is 1234, then you'd get:

1234FOO

That said, your regex seems to be wrong on more than one count. You say:

PROJECT_NUMBER.([ ]{2,}=.*)

Since you are not using any option for sed that would enable the use of Extended Regular Expressions, this would match the string PROJECT_NUMBER, followed by one character, followed by (, followed by 2 or more whitespaces, an = sign, until it encounters the last ) in the string.

Since you haven't mentioned anything about how the line in the file looks like, I'd assume that it's of the form:

PROJECT_NUMBER = 42.42

The following might work for you:

sed 's/\(PROJECT_NUMBER[ ]*=[ ]*\)[^ ]*/\1$VERSION/' filename

If invoking from within a Makefile, you'd need to double the $.

Upvotes: 1

Related Questions