Can't replace string with multiple spaces with sed in linux (Slackware). Please help!
Doing
sed -i "s/#DEFAULT_AMPLIFICATION___30/#DEFAULT_AMPLIFICATION___0/g" config.h does nothing and for every "_" there is an empty space. Due to the forum handling code I can't properly post with real spaces include (they get deleted into one space); perhaps some sort of anti spam mechanism or something to do with linux file-naming in general (assuming this board runs off Linux systems)? How do I replace the string #DEFAULT_AMPLIFICATION___30 with #DEFAULT_AMPLIFICATION___0? Every "_" is a space. Slackware64 14. Kind Regards, |
I can't see anything wrong with that command.
In fact, I just tried it and it seems to work fine here on my 32-bit Slackware 14.0 system (assuming you want to replace all occurrences of #DEFAULT_AMPLIFICATION 30 with #DEFAULT_AMPLIFICATION 0 in the file config.h). |
If you have an indeterminate number (or type, e.g. <tab>) you perhaps should use a class such as [[:space:]]+
sed supports regex extended. |
Strange. I went to edit my post but sure enough it shows plenty of spaces between "#DEFAULT_AMPLIFICATION 3". Guess there's problems with spaces in this forum too!
"DEFAULT_AMPLIFICATION___3" with every "_" being an empty space is what it should look like in my original post. I've edited my original post if you can still help. Kind regards, |
Please use [code][/code] tags to keep all formatting and when showing code or data.
|
please use
Code:
[code] and give an example of your config.h what should be replaced and what's happened. As it was already mentioned it should work. In case you have tabs also (not only spaces) you may need to use another syntax: Code:
sed -ri 's/(#DEFAULT AMPLIFICATION\s+)30/\10/g' config.h |
Code:
sed -ri 's/(#DEFAULT AMPLIFICATION\s+)0/\10/g' config.h Used your example but doesn't work... Tried in frame-buffer console but same results. Trying this with sdl_mixer source code in $SOURCE/timdity/config.h. This is what the section in config.h looks like: Code:
/* A somewhat arbitrary frequency range. The low end of this will |
Well unless I have missed something, none of the lines you have shown in your example match what you are searching for:
Code:
(#DEFAULT AMPLIFICATION\s+)0 |
Quote:
Tried: Code:
sed -i 's/(#DEFAULT AMPLIFICATION\s+)30/(#DEFAULT AMPLIFICATION\s+)0/g' config.h Regards |
still not sure what do you need would be much better to say not only it does not work but what would be the expected result. Try this, probably:
Code:
sed -ri 's/(#DEFAULT AMPLIFICATION\s+)\d+/\10/g' config.h |
As indicated by pan64, without -r your current attempts are also looking for the round brackets you have used.
|
Didn't work. Tried -ri with previous examples but nothing changes.
Trying to change the following line: Code:
#define DEFAULT_AMPLIFICATION 30 Code:
#define DEFAULT_AMPLIFICATION 0 |
Well again, I would point out that your example sed's and your before and after data do no match.
You state you start with: Code:
#define DEFAULT_AMPLIFICATION 30 Code:
sed -i 's/(#DEFAULT AMPLIFICATION\s+)30/(#DEFAULT AMPLIFICATION\s+)0/g' config.h 1. No -r option so all () will be interpreted as being part of the string which are not there 2. ALL sed searches are looking for lines starting with # and immediately followed by 'DEFAULT'. Again, not in your input data as line starts with '#define' 3. ALL sed's are searching for 'DEFAULT AMPLIFICATION', however the input has an underscore between the words. Again, no match 4. First sed will give incorrect output assuming search worked as '\s+' will be interpreted literally in the second half of sed As you can see, the issue here is not so much what you are getting wrong with sed, but your expression you are searching for is flawed and hence no changes are being made. |
Wow I was having so much fun with jungle bunnies in my head. Grail, you're absolutely right! After focusing I realized using
Code:
sed -ri 's/(#define DEFAULT_AMPLIFICATION\s+)30/#define DEFAULT AMPLIFICATION 0/g' config.h Regards |
Now that you have the correct search string, you can remove the brackets if you are not going to use the back reference (ie. \1). I assume this would be correct as you are removing
the underscore as well as replacing the number 30 to 0. To give you something else to think about, you can merely search for the line and then do a replace on only those things you need instead of the entire line. As an example, if we assume your original line: Code:
#define DEFAULT_AMPLIFICATION 30 Code:
sed -i '/DEFAULT_AMPLIFICATION/s/3//' config.h Hope that helps :) Should you need more details on sed, have a look here - http://www.grymoire.com/Unix/Sed.html |
All times are GMT -5. The time now is 12:33 PM. |