Hi Marcello,

Marcello Cruz wrote on Fri, Jan 22, 2010 at 10:31:18PM -0200:

> I've read the documentation about sed - sed(8), re_format(7) and
> /usr/share/doc/usd/15.sed/ - but I still don't realize how to make
> this command work:

First decide whether you want to use basic or extended regular
expressions.  Than stick to that.

> $ s/(^[A_Z]{1})([a-z]+)\.sgml/\1\2\.html/g

That's an *extended* regular expression, note the '+'.
It almost works:

  schwa...@rhea $ echo "Abc.sgml\nBcd.sgml" | \                     
  > sed -E 's/(^[A_Z]{1})([a-z]+)\.sgml/\1\2\.html/g' 
  Abc.html
  Bcd.sgml

Fix the "[A_Z]" to read "[A-Z]", and it already works a bit better.
But you can simplify it:

  schwa...@rhea $ echo "Abc.sgml\nBcd.sgml" | \                     
  > sed -E 's/^([A-Z].*)\.sgml$/\1.html/'         
  Abc.html
  Bcd.html

 * The '{1}' has no effect.
 * No need two have two groups of parantheses.
 * According to what you say, you want '.*', not '[a-z]+'.
 * You probably want to anchor at the end, too ('$').
 * No need to escape the '.' in the replacement.
 * The /g modifier is pointless with '^' at the beginning.

You see, there are multiple issues.

> As I read I must prefix the '{', '}', '(' and ')' with backslashes.

That would be *basic* regular expressions:

  schwa...@rhea $ echo "Abc.sgml\nBcd.sgml" | \             
  > sed 's/\(^[A-Z]\{1\}\)\([a-z]+\)\.sgml/\1\2\.html/g'
  Abc.html
  Bcd.html

Or, again, corrected and simplified:

  schwa...@rhea $ echo "Abc.sgml\nBcd.sgml" | \                             
  > sed 's/^\([A-Z].*\)\.sgml/\1.html/'              
  Abc.html
  Bcd.html

> Even if I do so, the command does not work.

When reporting problems, please paste the exact commands you are
typing.

[...]
> I think there is some bug with the implementation of sed or the
> "branch" (one or more pieces concatenated - as stated under
> re_format) is not supported with BRE.
[...]

No, i can't see any bug here.

Yours,
  Ingo

Reply via email to