I am trying to perform some modification on a typical g++ command line. I am trying to construct a regex looking for -o object_filename.o constructs. In order to test my matching pattern, I launch it in sed with an empty string as a substitution. But it does not work as expected since it removes nothing...
$echo "-o toto.o" | sed 's/-o [^ ]+//'
-o toto.o
You are missing a -E flag; without it, + is not treated as a regex meta-character:
$echo "-o toto.o" | sed -E 's/-o [^ ]+//'
The above produces an empty output, as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With