Answers:
在bash中,您可以执行以下操作:
$ str="abcdefgh"
$ foo=${str:2} # from the 3rd letter to the end
echo ${str:0:2}${foo^} # take the first three letters from str and capitalize the first letter in foo.
abCdefgh
在Perl中:
$ perl -ple 's/(?<=..)(.)/uc($1)/e; ' <<<$str
abCdefgh
要么
$ perl -ple 's/(..)(.)/$1.uc($2)/e; ' <<<$str
abCdefgh
$ARGV[0]=~而不是的以前版本遗留下来的<<<$str。谢谢。
bash可以与被缩短foo=${str:2}并且${foo^},其中只有大写字符串中的第一个字符。
另一个perl:
$ str="abcdefgh"
$ perl -pe 'substr($_,2,1) ^= " "' <<<"$str"
abCdefgh
一般形式为substr($_,n,1)这里n是要反转的情况下(基于0的索引)字母的位置。
当对带有空格的ASCII字符进行异或运算时,将其大小写反转。
~的perl解决方案?