You can do it using groups. If you have this file:
$ cat a
galaxy
ear
aardvak
Haaaaaaaaa
Ulaanbaatar
You can use this sed command:
$ sed 's/(.)1{1,}/U&/g' a
galaxy
ear
AArdvak
HAAAAAAAAA
UlAAnbAAtar
What does happen here? If we have a char, "packed" in a group ((.)
), and this group (1
) repeats itself one or more times (1{1,}
), then replace the matched part (&
) by its uppercased version (U&
).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…