我需要将文件中每一行的第一个字母更改为大写,例如
the bear ate the fish.
the river was too fast.
会成为:
The bear ate the fish.
The river was too fast.
- 该文档包含一些特殊字母:a, a, á, à, ǎ, ā, b, c, d, e, e, é, è, ě, ē, f, g, h, i, i, í, ì , ǐ, ī, j, k, l, m, n, o, o, ó, ò, ǒ, ō, p, q, r, s, t, u, u, ú, ù, ǔ, ü, ǘ 、 、 、 、 、 、 ū、 v、 w、 x、 y 和 z。
- 这些字母的大写形式为:A、A、Á、À、Ǎ、Ā、B、C、D、E、E、É、È、Ě、Ē、F、G、H、I、I、Í、 Ì、Ǐ、Ī、J、K、L、M、N、O、O、Ó、Ò、Ǒ、Ō、P、Q、R、S、T、U、U、Ú、Ù、Ǔ、Ü、 ε、ε、ε、ε、V、W、X、Y 和 Z。
如何将文件中每一行的首字母更改为大写?
Use sed
:
sed 's/^\(.\)/\U\1/' yourfile > convertedfile
小解释:
- the
^
代表一行的开始。
-
.
匹配任何字符
-
\U
转换为大写
-
\( ... \)
指定稍后要引用的部分(如\1
在这种情况下);这里的括号要被转义。
Do not try to redirect the output to the same file in one command (i.e. > yourfile
) as you will lose your data. If you want to replace in the same file then check out joelparkerhenderson's answer.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)