The sed syntax would be sed -e 's/ /%20/g', somebody correct me if I'm wrong, I'm not much of a sed user, but in vi I'd use 1,$s/ /%20/g. There is a space after the "s/" and before the next "/".
Could be a problem in the interpretation of space. / / will replace every single space, i.e. if there are three spaces between two charecters then it will replace them with %20%20.
If this is required ok but if you need to replace all white space between two charecters with one occurance of %20
i.e.
222 222 222 becomes 222%20%20222%20%20222
I am thinking on this as I suspect I may encounter the problem myself.
Well, he said, "any spaces" so I figured that's what he was looking for.
I had run a script called "machine_info" that I copied from the "Essential Systems Administration" manual and edited to my needs on my RS6000's. When the script finished I had to break down spaces and do other formatting to it to make a readable Excel spreadsheet. To do this I had to redefine my spaces. For instance I used that command and put in however many spaces I needed and replaced them with a character that did not exist in the output (i.e., s/{2spaceshere}/;/g) would put a ";" in the place of 2 spaces, I know it will work, it's kind of cumbersome, but it did the trick. There's probably a perl or maybe a troff solution, but I don't do troff, and the box didn't have perl so I went with what I had.
Just to expand on shail's regexp, between the "[" and "]" you need to enter a space and a tab. For example, using ^I to represent tab:
[tt]
s/[^I ]*/%20/g
[/tt]
Don't forget that the * in a regexp means "zero or more of the preceding character". As the preceding character is a tab or a space, this replaces any amount of whitespace with a single "%20". Remove the "*" if you want to replace every tab or space with "%20".
Cardy's solution is spot on, DGM's does not work on my Solaris instalation. [sig]<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>Top man[/sig]
Putting the "\" before the "+" is escaping the special regex meaning of "+" and turning it into a normal "+" character. So, "<space>\+" is looking for a literal "<space>+" character combination. Take the "\" out, and you've got a very similar solution to the "<two spaces>*" one. [sig]<p> Andy Bold<br><a href=mailto: > </a><br><a href= > </a><br>"I've probably made most of the mistakes already, so hopefully you won't have to..." Me, most days.[/sig]
'Fraid not Andy. I thought the same as you so I took the \ out but it still didn't work. I don't think + means 1-or-more of the previous character. I certainly haven't come across it (yet) in the excellent book 'sed and awk' by Dougherty & Robbins from O'Reilly. [sig][/sig]
Heck! This is what you get for doing too much perl! *grin* Looks like the "+" operator is a perlism, and I was getting confused. [sig]<p> Andy Bold<br><a href=mailto: > </a><br><a href= > </a><br>"I've probably made most of the mistakes already, so hopefully you won't have to..." Me, most days.[/sig]
Did anybody think about the Command "tr" which translates characters in a Stream?
[sig]<p>hnd<br><a href=mailto:hasso55@yahoo.com>hasso55@yahoo.com</a><br><a href= > </a><br> [/sig]
I had a go with it bt could not stop tr from replacing the new lines with new string, also had problems using %20 as a string. [sig]<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>Top man[/sig]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.