Reputation: 3922
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
Upvotes: 9
Views: 9263
Reputation: 276
Here is a single sed command that uses only POSIX sed features:
sed -e 'h;s,^\(.\).*$,\1,;y,ABCDEFGHIJKLMNOPQRSTUVWXYZ,abcdefghijklmnopqrstuvwxyz,;G;s,\
.,,'
These are two lines, the first line ending in a backslash to quote the newline character.
Upvotes: 0
Reputation: 17188
Pure Bash 4.0+ , parameter substitution:
>"$outfile" # empty output file
while read ; do
echo "${REPLY,}" >> "$outfile" # 1. character to lowercase
done < "$infile"
mv "$outfile" "$infile"
Upvotes: 2
Reputation: 454912
Try:
plat=`echo $plat |cut -c1 |tr '[:upper:]' '[:lower:]'``echo $plat |cut -c2-`
Upvotes: 2
Reputation: 206659
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.)
Upvotes: 12