I wish to replace all the backslashes (which appear on the same line with an include directive) with slashes.
Here's what I have until now..
echo '#include "..\etc\filename\yes"' | sed 's&\(#include.*\)\\&\1\/&g'
This works as I expect, but the problem is that it replaces only one \ at a time... If I want to replace all three in the above text, I have to run the sed command 3 times... The g flag at the end should make the replacements globally, no?
I'm using sed 4.2.1 on Ubuntu 11.10...
The problem is the way you're matching. The .* is greedy, so it matches the last backslash first and then thinks it's done. Try this:
... | sed '/^#include/s&\\&/&g'
That runs the substitutions only on lines matching the first pattern.
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