I've been working on a bash script to search for names of defines, and then grab the hex values for them and put them in the list. Once I have the list of names I'll attempt to search for "#define [name]" using -w to ensure exact match, and then awk '{ print $3 }' to grab the hex value.
However it works if the line in the header file is similar to
a.h:#define [name] 0x0001
But it does NOT work if it is similar to
a.h: #define [name] 0x0001
How can I get around this? I have tried this
grep -nrw "\s*#define[[:space:]]*$p" . --include=*.h | awk '{ print $3 }'
I thought the \s*
would ignore the leading whitespace before #define
but it doesn't. Am I doing something wrong?
-E
flag to use\s
#define
to be shifted from $1 to $2