Using Raku (formerly known as Perl_6)
~$ raku -ne 'if / <:Ll> / { $_.put } else { $_.lc.put };' file
#OR (more simply)
~$ raku -ne 'put / <:Ll> / ?? $_ !! $_.lc;' file
The first two answers below use Raku's -ne
non-autoprinting command line switches. The regex character class <:Ll>
stands for "Unicode Letter lower". The first answer above is obviously an if/else
construct. The second answer uses Raku's ternary operator ( < test > ??
True !!
False ).
MORE SOLUTIONS:
~$ raku -e 'for lines() { when / <:Ll> / {.put}; default {$_.lc.put} };' file
#OR
~$ raku -pe '$_ .= lc if not / <:Ll> /;' file
The third answer (first line in code block immediately above) uses Raku's "case" statement construction: when
and default
are used to satisfy the substitution criteria.
The fourth answer (second line in code block immediately above) uses Raku's -pe
autoprinting (sed-like) command line flags, in conjunction with Raku's .=
mutating-assignment operator.
Sample Input:
One, Two.
OnE, Two.
ONE, TWO.
ÜNICØDÉ
РУССКИЙ ЯЗЫК RUSSIAN
ΝΈΑ ΕΛΛΗΝΙΚΆ GREEK
"HEISS HEIẞ" GERMAN (WORD)
Sample Output (all code examples):
One, Two.
OnE, Two.
one, two.
ünicødé
русский язык russian
νέα ελληνικά greek
"heiss heiß" german (word)
The Raku answers handle Unicode (tested briefly above). For example, in the last line note the uppercase German ẞ
(U+1E9E) is successfully converted to lowercase German ß
(U+00DF). (This lettercasing was adopted into Unicode in 2008 and according to Wikipedia, "The capital letter was finally adopted as an option in standard German orthography in 2017.").
https://raku.org
https://docs.raku.org/language/operators#infix_??_!!
https://docs.raku.org/language/control#when
https://en.wikipedia.org/wiki/ß#Development_of_a_capital_form