I want to convert the 1st letter of each line to lower case up to the end of the file. How can I do this using shell scripting?
I tried this:
plat=`echo $plat |cut -c1 |tr [:upper:] [:lower:]``echo $plat |cut -c2-`
but this converts only the first character to lower case.
My file looks like this:
Apple
Orange
Grape
Expected result:
apple
orange
grape
You can apply the `tr` command for converting the content of any text file from upper to lower or lower to upper.
How do I convert uppercase words or strings to a lowercase or vise versa on Unix-like / Linux bash shell? Use the tr command to convert all incoming text / words / variable data from upper to lower case or vise versa (translate all uppercase characters to lowercase).
'^' symbol is used to convert the first character of any string to uppercase and '^^' symbol is used to convert the whole string to the uppercase. ',' symbol is used to convert the first character of the string to lowercase and ',,' symbol is used to convert the whole string to the lowercase.
You can do that with sed
:
sed -e 's/./\L&/' Shell.txt
(Probably safer to do
sed -e 's/^./\L&\E/' Shell.txt
if you ever want to extend this.)
Try:
plat=`echo $plat |cut -c1 |tr '[:upper:]' '[:lower:]'``echo $plat |cut -c2-`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With