Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert first letter of given file to lower case

Tags:

linux

bash

shell

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
like image 341
Sijith Avatar asked Apr 09 '12 07:04

Sijith


People also ask

How will you translate file contents from small to capital letters?

You can apply the `tr` command for converting the content of any text file from upper to lower or lower to upper.

How do you change uppercase to lowercase in UNIX?

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).

How do I make the first letter capital in Linux?

'^' 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.


2 Answers

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.)

like image 94
Mat Avatar answered Oct 26 '22 11:10

Mat


Try:

plat=`echo $plat |cut -c1 |tr '[:upper:]' '[:lower:]'``echo $plat |cut -c2-`
like image 31
codaddict Avatar answered Oct 26 '22 10:10

codaddict