GNU sed processes valid multibyte characters in multibyte locales
(e.g. UTF-8). 7
The following example uses the Greek letter Capital Sigma
(Σ,
Unicode code point 0x03A3). In a UTF-8 locale,
sed correctly processes the Sigma as one character despite
it being 2 octets (bytes):
$ locale | grep LANG LANG=en_US.UTF-8 $ printf 'a\u03A3b' aΣb $ printf 'a\u03A3b' | sed 's/./X/g' XXX $ printf 'a\u03A3b' | od -tx1 -An 61 ce a3 62
To force sed to process octets separately, use the C locale
(also known as the POSIX locale):
$ printf 'a\u03A3b' | LC_ALL=C sed 's/./X/g' XXXX
Some regexp edge-cases depends on the operating system and libc implementation. The examples shown are known to work as-expected on GNU/Linux systems using glibc.