回答:
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文字をxorすると、大文字と小文字が逆になります。
~でperl解決しますか?