Supposing I have:sdk.h:#define foo 1#define bar 1app.h:#define foo 0How can I generate a merged.h that looks like this, given I want app.h to redefine anything already defined in sdk.h:#define foo 0#define bar 1One approach might be don't do this, just let the preprocessor do it for you. I've tried that and it's not going to work for my situation I don't think. I'm really looking for an approach using a basic shell script.
How do I merge two C header files, such that re- #defines are removed?
text processing;c
If the order of the contents in the header files is not important, you could do something like this:$ awk '/#define/{a[$2]=$3; next}1;END{for(i in a){print #define,i,a[i]}}' sdk.h app.h #define foo 0#define bar 1Note that any lines not containing #define will be printed first. 