Convert the first letter of this file to lowercase

I want to convert the 1st letter of each line to lowercase to the end of the file. How to do this using shell scripts?

I tried this:

plat=`echo $plat |cut -c1 |tr [:upper:] [:lower:]``echo $plat |cut -c2-` 

but this only converts the first character to lowercase.

My file is as follows:

 Apple Orange Grape 

Expected Result:

 Apple Orange Grape 
+6
source share
4 answers

You can do this with sed :

 sed -e 's/./\L&/' Shell.txt 

(Probably safer to do

 sed -e 's/^./\L&\E/' Shell.txt 

if you want to expand this.)

+6
source

Try:

 plat=`echo $plat |cut -c1 |tr '[:upper:]' '[:lower:]'``echo $plat |cut -c2-` 
+2
source

Pure Bash 4.0+, replacement of parameters:

 >"$outfile" # empty output file while read ; do echo "${REPLY,}" >> "$outfile" # 1. character to lowercase done < "$infile" mv "$outfile" "$infile" 
+2
source

Here is one sed command that uses only the POSIX sed functions:

 sed -e 'h;s,^\(.\).*$,\1,;y,ABCDEFGHIJKLMNOPQRSTUVWXYZ,abcdefghijklmnopqrstuvwxyz,;G;s,\ .,,' 

These are two lines, the first line ending with a backslash to quote a newline character.

0
source

Source: https://habr.com/ru/post/912737/


All Articles