[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] how to change the first character into upper case



Tony van der Hoff wrote:
> lina wrote:
> >Here is what I came up with so far:
> >  echo "NELSON ARISPE, EDUARDO ROJAS, AND HARVEY B. POLLARD" | sed 's/\([A-Z]\)\([A-Z]+\)/\1\L\2/g'
> >not work.
>
> The "+" form for one or more characters is not supported by sed.
> This works :
> sed 's/\([A-Z]\)\([A-Z]*\)/\1\L\2/g'

The '+' is an ERE (Extended Regular Expression).  Sed handles BREs
(Basic Regular Expressions).  In the beginning almost all tools only
handled BREs.  They take much less memory.  It wasn't until later that
EREs became popular.  Sed dates from the BRE time.

GNU sed as an extension will use EREs if you give it the
-r,--regexp-extended option.  Or if you quote the ERE.  Most people
quote the ERE (with a backslash) but either works.  It must remain
compatible with regular sed and a quoted plus isn't valid in regular
sed and so can be used as an extension syntax.

  sed --regexp-extended 's/\([A-Z]\)\([A-Z]+\)/\1\L\2/g'
Or:
  sed 's/\([A-Z]\)\([A-Z]\+\)/\1\L\2/g'

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: