2

I have a makefile recipe that prints source files and header files. I'm trying to fixup the output to use in an Autotools recipe. An output from make sources is shown below.

I need to remove words that end in simd.cpp. SIMD files need special architectural flags so they don't get put in the list. I found a similar question at stack overflow but it is not removing the filenames with simd in them.

Here are my attempts to match words and remove them from the stream. None of them removed all of the words. In fact I don't believe any of the simd words were removed.

  • sed -e 's|\b[*]\-simd.cpp[^ ]*||g'
  • sed -e 's|\b[*]-simd.cpp[^ ]*||g'
  • sed -e 's|\b*-simd.cpp[^ ]*||g'
  • sed -e 's|\b*\-simd.cpp[^ ]*||g'
  • sed -e 's|\b*\-simd.cpp||g'
  • sed -e 's|\b*-simd.cpp||g'
  • sed -e 's|\b-simd.cpp||g'

As I understand things from the stack overflow question, \b matches words, leading * captures the first part of the word, and -simd.cpp[^ ]* matches the last part of the word including the trailing space.

What am I misunderstanding and how do I fix it?


Here is the output that needs the *-simd.cpp words removed.

$ make sources | fold -w80 -s
***** Library sources *****
cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp algebra.cpp algparam.cpp
arc4.cpp aria-simd.cpp aria.cpp ariatab.cpp asn.cpp authenc.cpp base32.cpp
base64.cpp basecode.cpp bfinit.cpp blake2-simd.cpp blake2.cpp blowfish.cpp
blumshub.cpp camellia.cpp cast.cpp casts.cpp cbcmac.cpp ccm.cpp chacha.cpp
cham-simd.cpp cham.cpp channels.cpp cmac.cpp crc-simd.cpp crc.cpp default.cpp
des.cpp dessp.cpp dh.cpp dh2.cpp dll.cpp dsa.cpp eax.cpp ec2n.cpp eccrypto.cpp
ecp.cpp elgamal.cpp emsa2.cpp eprecomp.cpp esign.cpp files.cpp filters.cpp
fips140.cpp fipstest.cpp gcm-simd.cpp gcm.cpp gf256.cpp gf2_32.cpp gf2n.cpp
gfpcrypt.cpp gost.cpp gzip.cpp hc128.cpp hc256.cpp hex.cpp hight.cpp hmac.cpp
hrtimer.cpp ida.cpp idea.cpp iterhash.cpp kalyna.cpp kalynatab.cpp keccak.cpp
lea-simd.cpp lea.cpp luc.cpp mars.cpp marss.cpp md2.cpp md4.cpp md5.cpp
misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp neon-simd.cpp network.cpp
oaep.cpp osrng.cpp padlkrng.cpp panama.cpp pkcspad.cpp poly1305.cpp
polynomi.cpp ppc-simd.cpp pssr.cpp pubkey.cpp queue.cpp rabbit.cpp rabin.cpp
randpool.cpp rc2.cpp rc5.cpp rc6.cpp rdrand.cpp rdtables.cpp rijndael-simd.cpp
rijndael.cpp ripemd.cpp rng.cpp rsa.cpp rw.cpp safer.cpp salsa.cpp scrypt.cpp
seal.cpp seed.cpp serpent.cpp sha-simd.cpp sha.cpp sha3.cpp shacal2-simd.cpp
shacal2.cpp shark.cpp sharkbox.cpp simeck-simd.cpp simeck.cpp simon-simd.cpp
simon.cpp skipjack.cpp sm3.cpp sm4-simd.cpp sm4.cpp socketft.cpp sosemanuk.cpp
speck-simd.cpp speck.cpp square.cpp squaretb.cpp sse-simd.cpp strciphr.cpp
tea.cpp tftables.cpp threefish.cpp tiger.cpp tigertab.cpp trdlocal.cpp
ttmac.cpp tweetnacl.cpp twofish.cpp vmac.cpp wait.cpp wake.cpp whrlpool.cpp
xtr.cpp xtrcrypt.cpp zdeflate.cpp zinflate.cpp zlib.cpp

...
3

Inside of [], * is a literal character, and outside it's a quantifier.

I don't really see any value in using word boundary anchors (\b) here - you probably want to match something like a non-empty sequence of alphanumeric characters followed by the -simd.cpp suffix e.g. s/[[:alnum:]]*-simd.cpp//g

We can check what that matches using grep:

$ grep -o '[[:alnum:]]*-simd.cpp' sources 
aria-simd.cpp
blake2-simd.cpp
cham-simd.cpp
crc-simd.cpp
gcm-simd.cpp
lea-simd.cpp
neon-simd.cpp
ppc-simd.cpp
rijndael-simd.cpp
sha-simd.cpp
shacal2-simd.cpp
simeck-simd.cpp
simon-simd.cpp
sm4-simd.cpp
speck-simd.cpp
sse-simd.cpp

If an alphanumeric string is not general enough, you could instead match a sequence of non-whitespace characters [^[:blank:]]*

  • Yeah, that's nice thanks. It is also easier to read. – user56041 Jul 26 '18 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy