I'm having trouble getting a string tool to provide what I need (due to my ignorance). I have a string based on CPU features. The string will change as different processors offer different features:
# Example from a modern Core i5 4th gen
SUNCC_CXXFLAGS="-D__SSE2__ -D__SSE3__ -D__SSSE3__ -D__SSE4_1__ -D__SSE4_2__ -D__AES__ -D__PCLMUL__ __AVX__ ..."
The string works great for Sun Studio 12.3 and above. For Sun Studio 12.2 and below, I can only use SSE2, SSE3, SSSE3, SSE4.1 and SSE4.2. AES and above defines cause an obscure error, so they must be filtered out of the flags.
Put another way I need the intersection of the two sets:
# Cannot use AES and above for SunCC 12.2
ALLOWED_CXXFLAGS="-D__SSE2__ -D__SSE3__ -D__SSSE3__ -D__SSE4_1__ -D__SSE4_2__"
# New processor, needs to be filtered due to old compiler
SUNCC_CXXFLAGS="-D__SSE2__ -D__SSE3__ -D__SSSE3__ -D__SSE4_1__ -D__SSE4_2__ -D__AES__ -D__PCLMUL__ __AVX__ ..."
I've seen a number of questions and answers with awk matching (and non-matching) regexes and lines. But I need to filter based on tokens in a single line.
I tried the following, which does not produce expected results:
$ echo "-D__SSE2__ -D__SSE3__ -D__SSSE3__ -D__SSE4_1__ -D__SSE4_2__ -D__AES__ -D__PCLMUL__" | \
nawk '!/(-D__SSE2__|-D__SSE3__|-D__SSSE3__)/'
$
Another twist: this is Solaris, so the tools don't have a lot of the options present in GNU tools. Its one of the reasons I tried awk instead of sed or grep.
How can I filter out the tokens that don't match my set of tokens?
nawk '{gsub(/-D__SSE2__|-D__SSE3__|-D__SSSE3__/,"")}1'but I would think it's just as likely that your version of sed supports a BRE of the formsed 's/-D__SSE2__\|-D__SSE3__\|-D__SSSE3__//g'CXXFLAGSonly includes SSE2.