将给定文件的第一个字母转换为小写

Sij*_*ith 7 linux bash shell

我想将每行的第一个字母转换为小写,直到文件的末尾.如何使用shell脚本执行此操作?

我试过这个:

plat=`echo $plat |cut -c1 |tr [:upper:] [:lower:]``echo $plat |cut -c2-`
Run Code Online (Sandbox Code Playgroud)

但这只会将第一个字符转换为小写字母.

我的文件看起来像这样:

Apple
Orange
Grape
Run Code Online (Sandbox Code Playgroud)

预期结果:

apple
orange
grape
Run Code Online (Sandbox Code Playgroud)

Mat*_*Mat 9

你可以这样做sed:

sed -e 's/./\L&/' Shell.txt
Run Code Online (Sandbox Code Playgroud)

(可能比较安全

sed -e 's/^./\L&\E/' Shell.txt
Run Code Online (Sandbox Code Playgroud)

如果你想扩展它.)

  • 这个POSIX是sed还是使用GNU扩展?这在Mac OS X上对我不起作用. (2认同)