change the first character of the line to uppercase in a text file

Tim Chase python.list at tim.thechases.com
Fri Jun 26 16:59:35 EDT 2009


powah wrote:
> How to change the first character of the line to uppercase in a text
> file?
> e.g.
> input is:
> abc xyz
> Bd ef
> gH ij
> 
> output should be:
> Abc xyz
> Bd ef
> GH ij

While you're asking the Python list, I'd just use GNU sed:

   sed -i 's/./\U&/' myfile.txt

I don't know if the "\U"=="make the replacement uppercase" is a 
GNU-sed specific thing, but it works here on my Debian box's 
version 4.1.5 when I tested it.

-tkc







More information about the Python-list mailing list