1

I have a UTF file in uppercase, and I want to change all words to lowercase.

I have tried:

`tr '[:upper:]' '[:lower:]' < input.txt > output.txt`

But that changes only characters without an accent.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
liborw
  • 842
  • 1
  • 8
  • 22

3 Answers3

4

Finally the simplest way I found is to use AWK:

awk '{print tolower($0)}' < input.txt > output.txt
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
liborw
  • 842
  • 1
  • 8
  • 22
  • 1
    This is, indeed, the "correct" way to go about it, since `awk` is Unicode-aware and `tr` isn't. This should be the accepted answer. – DevSolar Dec 15 '14 at 09:29
1

This is because the default character classes only work on standard ASCII, which does not include most of the international accented characters. If you have a defined set of those characters, the easiest way would be to simply add the mapping from special uppercase character to special lowercase character manually:

tr 'ÄÖU[:upper:]' 'äöü[:lower:]'

If you only have a few accented characters, this is workable.

JeSuisse
  • 349
  • 1
  • 6
0

No, the issue is that tr is not Unicode aware.

$ grep -o '[[:upper:]]' <<< JalapeÑo
J
Ñ
$ tr '[:upper:]' '[:lower:]' <<< JalapeÑo
jalapeÑo

The reason to use [:upper:], etc., is in order to handle characters outside ASCII. Otherwise, you could just use [A-Z] and [a-z]. That's also why PCRE has a character class called [:ascii:]]:

$ perl -pe 's/[[:ascii:]]//g' <<< jalapeño
ñ
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • You're right! But using character classes never worked for me up to now, neither in unicode nor in latin1, so I gave up on it a long time ago and always do it manually :-( – JeSuisse Jul 17 '10 at 10:42