awk de service.
echo "abcdefgh" | awk '{print substr($0,1,1) toupper(substr($0,2,2)) substr($0,4)}'
La sortie sera la suivante.
aBCdefgh
Si vous avez un INPUT_FILE et que vous souhaitez enregistrer les modifications en même INPUT_FILE.
awk '{print substr($0,1,1) toupper(substr($0,2,2)) substr($0,4)}' Input_file > temp_file && mv temp_file Input_file
Explication: S'il vous plaît passer au-dessus du code comme ceci est uniquement à des fins d'explication.
echo "abcdefgh" ##using echo command to print a string on the standard output.
| ##Pipe(|) is used for taking a command's standard output to pass as a standard input to another command(in this case echo is passing it's standard output to awk).
awk '{ ##Starting awk here.
##Print command in awk is being used to print anything variable, string etc etc.
##substring is awk's in-built utility which will allow us to get the specific parts of the line, variable. So it's syntax is substr(line/variable,starting point of the line/number,number of characters you need from the strating point mentioned), in case you haven't mentioned any number of characters it will take all the characters from starting point to till the end of the line.
##toupper, so it is also a awk's in-built utility which will covert any text to UPPER CASE passed to it, so in this case I am passing 2nd and 3rd character to it as per OP's request.
print substr($0,1,1) toupper(substr($0,2,2)) substr($0,4)}'
'^' est redondant, la première correspondance commence à gauche et '.' correspond toujours au premier caractère – 123
Merci! Pouvez-vous s'il vous plaît m'aider à comprendre la commande? :-). Par exemple; Je ne comprends pas comment seuls "bc" ont été capitalisés. – Dipak
@Dipak, voir mon explication – RomanPerekhrest