As I read I must prefix the '{', '}', '(' and ')' with backslashes. Even
if
I do so, the command does not work. The command should take a filename
starting with a capital letter followed with the extension 'sgml' and
translate the extension to 'html'.
1. Always show the commands you're actually running.
$ echo 'Teste.sgml' | sed 's/\(^[A-Z]\{1\}\)\([a-z]+\)/\1\2\.html/g'
This command is supposed to - only - change the file extension from ".sgml"
to ".html" on files starting with an uppercase letter, following one or more
lowercase letters.
I know [A_Z] is incorrect so, I'm sorry. But this command was taken from
http://www.bsd.org/regexintro.html exactly as it appears there. Also, the
explanation of the command in there seems to be wrong.
2. If you actually did type [A_Z], that's wrong.
I know it, I'm sorry, I should've correct it on my message.
3. 's/\([A-Z][a-z]*\)\.sgml/\1.html/g'
Thank you. It really works! But the problem is a bit complex. The original
idea is to identify two parts of the original string. For example, the file
named 'Teste.html' should be translated to 'T_new_este.sgml'. Accordingly to
the example from http://www.bsd.org/regexintro.html it should be possible to
identify 'T' as '\1' in the replacement string and 'este' as '\2' in the
replacement string. sed seems not to understand what "branch" is or I don't
know how to concatenate two "pieces". The definitions for "branch" and
"pieces" are in re_format(7), as below:
"An ERE is one** or more non-empty** branches, separated by `|'. It
matches anything that matches one of the branches.
A branch is one** or more pieces, concatenated. It matches a match for
the first, followed by a match for the second, etc.
A piece is an atom possibly followed by a single** `*', `+', `?', or
bound. An atom followed by `*' matches a sequence of 0 or more matches
of the atom. An atom followed by `+' matches a sequence of 1 or more
matches of the atom. An atom followed by `?' matches a sequence of 0
or
1 matches of the atom"
Rgds
Marcello
PS: Sorry for grammar errors, I'm not a native english person.