Thanks, this is valid in Ruby, but I understand such a operation is not
feasible with "sed" command, is it?
I'm not sure yet about if I'll need to do this script in Ruby or Shell.
Thanks a lot.
···
El Domingo, 14 de Diciembre de 2008, David A. Black escribió:
Thanks, this is valid in Ruby, but I understand such a operation is
not feasible with "sed" command, is it?
I'm not sure yet about if I'll need to do this script in Ruby or
Shell.
Thanks a lot.
sed '/^X-Level: /s/\*/X/g'
~]$ echo "X-Level: ****" | sed '/^X-Level: /s/\*/X/g'
X-Level: XXXX
~]$ echo "X-Level: ***********" | sed '/^X-Level: /s/\*/X/g'
X-Level: XXXXXXXXXXX
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
Thanks, this is valid in Ruby, but I understand such a operation is not
feasible with "sed" command, is it?
I'm not sure yet about if I'll need to do this script in Ruby or Shell.
not sure if I understand what you're trying to do.. but it sounds like ***
is a number right?
so
text.tr('*','X')
becomes
text.tr('\d','X')
HTH
/Shawn
···
On Mon, Dec 15, 2008 at 9:12 AM, XY$ <kwicher@gmail.com> wrote:
On Dec 15, 2:42 pm, Mark Thomas <m...@thomaszone.com> wrote:
> On Dec 14, 1:33 pm, Iñaki Baz Castillo <i...@aliax.net> wrote:
>
> > Hi, I'm getting crazy to get a theorically easy substitution:
>
> > I've a file with a header:
> > X-Level: ***
> > where the number of "*" is variable (from 0 up to 10).
>
> > And I just want to replace "*" by "X", so get:
> > X-Level: XXX
>
> > I don't get it since I don't know how to replace ANY number of "*" with
the
> > same number of "X" just in the header "X-Level".
>
> Since I haven't seen the obvious answer yet...
>
> text.tr('*','X')
>
> -- Mark.
Mark,
The request was to make the replacement only in the header, isn't it?
Pardin, you probably won't need to backware that meta character.
sed '/^X-Level: /s/*/X/g'
···
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
No, because you just changed the problem. The specified input was the whole
string, not only the part of the string that should change. And the desired
output was that whole string with the part that should be changed, changed
and the rest as-is.
You could of course do
text.sub(/X-Level: \*+/) {|header| header.tr("*","X") }
but that's not neccessarily simpler than the already offered solutions.
As we are strolling OT alreeady It is turing complete, and someone
wrote a web server in sed.
But nobody knows what happened to him, a sed story....
R.
···
On Sun, Dec 14, 2008 at 10:15 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
El Domingo, 14 de Diciembre de 2008, David A. Black escribió:
You are correct, of course. And that's what I was trying to imply,
that it was only solving one piece of the problem. I guess I should
have explained it, rather than be glib with my response. If the header
was easily (or already) isolated, it would be a simple solution. But
that information was not given by the OP.
···
On Dec 16, 7:09 am, Sebastian Hungerecker <sep...@googlemail.com> wrote:
Mark Thomas wrote:
> excuse me...
> header.tr('*','X')
> Better?
No, because you just changed the problem. The specified input was the whole
string, not only the part of the string that should change. And the desired
output was that whole string with the part that should be changed, changed
and the rest as-is.
You could of course do
text.sub(/X-Level: \*+/) {|header| header.tr("*","X") }
but that's not neccessarily simpler than the already offered solutions.