Kent's answer did not solve my issue but I have not provided him all my constraints. My csv input file is like:
sfou;STéphane Foù - stephane.fou@example.com;;
fbar;frédéric bâr - frederic.bar@example.com;;
hnoel;Hélène NOËL - helene.noel@example.com;;
The sed script shall capitalize the names only:
sfou;Stéphane Foù - stephane.fou@example.com;;
8945;Frédéric Bâr - frederic.bar@example.com;;
hnoel;Hélène Noêl - helene.noel@example.com;;
Based on Kent's help, I successfully passed this script:
LC_ALL=fr_FR sed -r 's/(\w)(\w*) /\U\1\L\2 /g' test.cvs
Other locales do not give the right result:
$ LANG=fr_FR.utf8 LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;
$ LANG=C LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;
$ LANG=en_US.utf8 LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;
Locales en_US
and fr_FR
(without .utf8
) are OK:
$ LANG=en_US LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;[Stéphane] [Foù] - stephane.fou@example.com;;
fbar;[Frédéric] [Bâr] - frederic.bar@example.com;;
hnoel;[Hélène] [Noël] - helene.noel@example.com;;
$ LANG=fr_FR LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;[Stéphane] [Foù] - stephane.fou@example.com;;
fbar;[Frédéric] [Bâr] - frederic.bar@example.com;;
hnoel;[Hélène] [Noël] - helene.noel@example.com;;
Note: I have discovered \w
from CodeGnome's links.